c# - Handle navigation keys in TextBox inside DataGridView -
we have datagridview data in form. enable quick search added textbox datagridview.controls , highlight cells contain text textbox.
however there issue. datagridview "swallow" left
arrow, right
arrow, home , end (with or without shift) keys even if cursor in textbox, , user cannot change caret position or select text keyboard.
textbox generates previewkeydown
event , nothing more happens
simplified code:
public partial class testform : form { public testform() { initializecomponent(); var txt = new textbox { dock = dockstyle.bottom }; var dgv = new datagridview { dock = dockstyle.fill, columncount = 3, rowcount = 5 }; dgv.controls.add(txt); controls.add(dgv); dgv.previewkeydown += dgvonpreviewkeydown; dgv.keydown += dgvonkeydown; txt.previewkeydown += txtonpreviewkeydown; txt.keydown += txtonkeydown; } private void dgvonpreviewkeydown(object sender, previewkeydowneventargs e) { debug.writeline(string.format("dgv key preview {0}", e.keycode)); e.isinputkey = true; } private void dgvonkeydown(object sender, keyeventargs e) { debug.writeline(string.format("dgv key {0}", e.keycode)); } private void txtonpreviewkeydown(object sender, previewkeydowneventargs e) { debug.writeline(string.format("txt key preview {0}", e.keycode)); } private void txtonkeydown(object sender, keyeventargs e) { debug.writeline(string.format("txt key {0}", e.keycode)); } }
type 123
in textbox , try left
arrow, right
arrow, home
or end
. datagridview change selected cell textbox caret doesn't move
what can done make sure textbox receive keys , change caret position or select text?
have tried adding textbox main form instead of dgv?
controls.add(txt); controls.add(dgv); txt.previewkeydown += dgvonpreviewkeydown; txt.keydown += dgvonkeydown; txt.previewkeydown += txtonpreviewkeydown; txt.keydown += txtonkeydown;
Comments
Post a Comment