Autocomplete - add and get only the text that the user has entered into the combobox

I have ComboBox

one that I set up like this:

this.cmbCustomerJob.DisplayMember = "display";
this.cmbCustomerJob.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.cmbCustomerJob.AutoCompleteSource = AutoCompleteSource.ListItems;
this.cmbCustomerJob.DropDownStyle = ComboBoxStyle.DropDown;

      

However I fiddled with the event KeyPressed

to prevent the user from typing a new term in ComboBox

, however when I do cmbCustomerJob.Text

it returns even the suggested part, how can I only get what the user typed?

+1


source to share


1 answer


I found the answer, I did this:

strNew = ((ComboBox)sender).Text.Substring(0, ((ComboBox)sender).SelectionStart) + c.ToString();

      



It grabs Text

from the start ( 0

) to the start of the selection ( SelectionStart

), c.ToString()

is thisKeyPressEventArgs.KeyChar

+1


source







All Articles