views:

327

answers:

1

I have a ComboBox 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'm messing with the keypressedevent to prevent the user from entering a new term into the combobox, however when I do cmbCustomerJob.Text it returns even the suggested portion, how can I get only what the user has typed?

Thanks.

A: 

I found the answer, I did this: strNew = ((ComboBox)sender).Text.Substring(0, ((ComboBox)sender).SelectionStart) + c.ToString();

It grabs the text from the start (0) to were the selection begins (SelectionStart), the c.ToString() is the KeyPressEventArgs.KeyChar

Malfist