i have form textbox , datagridview. when user pressed arrow (up/down) browses through datagridview , when user pressed other key sends textbox.
it's not working, when datagridview has focus , user press letter key, changes focus textbox, no text sent.
my code:
protected overrides function processcmdkey(byref msg system.windows.forms.message, byval keydata system.windows.forms.keys) boolean if keydata = keys.down or keydata = keys.up grid.focus() return mybase.processcmdkey(msg, keydata) elseif not me.activecontrol.equals(txtfiltro) me.activecontrol = txtfiltro txtfiltro.focus() txtfiltro.select() return mybase.processcmdkey(msg, keydata) end if return mybase.processcmdkey(msg, keydata) end function
the key sent before change focus... :(
you'll want make sure have property "keypreview" set true on form has datagridview , textbox.
then on keydown event form try this:
private sub form1_keydown(sender object, e system.windows.forms.keyeventargs) handles me.keydown if e.keycode = keys.up or e.keycode = keys.down datagridview1.focus() else e.handled = true textbox1.focus() if textbox1.textlength = 0 textbox1.text += chrw(e.keyvalue) textbox1.selectionstart = 1 end if end if end sub
the last part trap see if want whatever key pressed passed text box. ignored if don't need that. if go using arrow keys should refocus datagridview.
probably not you're looking for. think can on right track.
Comments
Post a Comment