vb.net - Issue with combobox autocomplete -
vb.net - Issue with combobox autocomplete -
i trying incorporate 3 comboboxes functional gui consist of textboxes, numericupdown controls , comboboxes. on form have navigation keyboard (me.selectnextcontrol) keys , down. happens? when step in gui first time work ok , can move up/down keyboard expected.
problem becomes when edit combobox in midle of gui , set this:
mycombo.autocompletemode = autocompletemode.suggestappend mycombo.autocompletesource = autocompletesource.customsource mycombo.autocompletecustomsource = myautocompletestringcollection
problem when come combobox navigation loop don't keypress (up or downwards keys) anymore because combobox takes them itselfs purpose (change index).
i seek mycombo.autocompletesource = autocompletesource.customsource
after combobox_leave turns off autocomplete not wanted.
question is: here possible set described combobox after usage in mode @ origin of program, when not edited, can navigate keyboard through such comboboxes @ initial way autosuggest alternative remain enabled if need edit again.
edited: here simple illustration shows problem:
public class form1 private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load dim tb new textbox dim cbb new combobox dim tbb new textbox dim b1 new button dim b2 new button me .keypreview = true .size = new size(350, 200) .controls .add(tb) tb .tabindex = 0 .location = new point(95, 20) .text = "this is" end .add(cbb) cbb .tabindex = 1 .items.addrange(new string() {"alabama", "africa", "australia", "grenland"}) .location = new point(95, 50) .text = "an example" .dropdownstyle = comboboxstyle.dropdown .autocompletemode = autocompletemode.suggestappend .autocompletesource = autocompletesource.listitems end .add(tbb) tbb .tabindex = 2 .location = new point(95, 80) .text = "textbox" end .add(b1) b1 .tabstop = false .location = new point(90, 130) .text = "nothing" end .add(b2) b2 .tabstop = false .location = new point(170, 130) .text = "exit" addhandler b2.click, addressof b2_click end end end end sub private sub form1_keydown(byval sender object, byval e system.windows.forms.keyeventargs) handles me.keydown if e.keycode = keys.up e.handled = true me.selectnextcontrol(me.activecontrol, false, true, true, true) end if if e.keycode = keys.down e.handled = true me.selectnextcontrol(me.activecontrol, true, true, true, true) end if end sub private sub b2_click(byval sender object, byval e system.eventargs) me.close() end sub end class
when start programme pass several times through controls key downwards arrow. stop on combobox , type letter "a", seek navigate 1 time again key downwards arrow.
public class form1 private tb new textbox private cbb new combobox private tbb new textbox private b1 new button private b2 new button private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load addhandler cbb.previewkeydown, addressof cbb_previewkeydown addhandler tb.previewkeydown, addressof tb_previewkeydown addhandler tbb.previewkeydown, addressof tbb_previewkeydown me.size = new size(350, 200) tb .parent = me .tabindex = 0 .location = new point(95, 20) .text = "this is" end cbb .parent = me .tabindex = 1 .items.addrange(new string() {"alabama", "africa", "australia", "grenland"}) .location = new point(95, 50) .text = "an example" .dropdownstyle = comboboxstyle.dropdown .autocompletemode = autocompletemode.suggestappend .autocompletesource = autocompletesource.listitems end tbb .parent = me .tabindex = 2 .location = new point(95, 80) .text = "textbox" end b1 .parent = me .tabstop = false .location = new point(90, 130) .text = "nothing" end b2 .parent = me .tabstop = false .location = new point(170, 130) .text = "exit" addhandler b2.click, addressof b2_click end end sub private sub tb_previewkeydown(byval sender object, byval e system.windows.forms.previewkeydowneventargs) if e.keycode = keys.up tbb.focus() if e.keycode = keys.down cbb.focus() end sub private sub cbb_previewkeydown(byval sender object, byval e system.windows.forms.previewkeydowneventargs) if e.keycode = keys.up cbb.autocompletemode = autocompletemode.none tb.focus() cbb.autocompletemode = autocompletemode.suggestappend if not cbb.items.contains(cbb.text) cbb.text = "" end if if e.keycode = keys.down cbb.autocompletemode = autocompletemode.none tbb.focus() cbb.autocompletemode = autocompletemode.suggestappend if not cbb.items.contains(cbb.text) cbb.text = "" end if end sub private sub tbb_previewkeydown(byval sender object, byval e system.windows.forms.previewkeydowneventargs) if e.keycode = keys.up cbb.focus() if e.keycode = keys.down tb.focus() end sub private sub b2_click() me.close() end sub end class
i modified code. , now, it's working. :)
vb.net
Comments
Post a Comment