Selecting an item in comboBox by typing

后端 未结 2 1982
慢半拍i
慢半拍i 2020-12-24 11:01

I\'ve a combobox that has hundreds item in it. User must be able to type the text into the combobox . While the user is typing the text, the item that starting with the type

相关标签:
2条回答
  • 2020-12-24 11:43

    You will have to hook up to the TextChanged event. When the text changes, filter the list (using a DataView) and take the text of the first result, setting the text of the combo box to that. You would have to have a check in your handler of course, to determine whether or not to handle the event (when you change the text, another TextChanged event would be fired). Of course, you also want to highlight the text that they typed in, and place the caret at the appropriate position.

    0 讨论(0)
  • 2020-12-24 11:46
    comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
    comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
    
    0 讨论(0)
提交回复
热议问题