PRMiller2
Technical User
- Jul 30, 2010
- 123
I have a combobox which is populated with a dataset and autocomplete enabled on MainForm_Load:
The combobox functions as desired: when typing the first few letters of a client, that client can be selected by pressing <TAB> or <ENTER>, the ValueMember and DisplayMember are both changed properly, and the focus is moved to the next control. However, the text from the DisplayMember remains fully highlighted, even while the user types data into another control.
If an item is selected using the dropdown box rather than autocomplete, the appropriate DisplayMember is displayed but does not remain highlighted -- in other words, the desired visual effect.
How do I correct the issue with autocomplete? I have experimented with trapping the tab key on a KeyDown event, but that text remains highlighted.
Thanks,
Paul
Code:
private void FillClientComboBox()
{
try
{
string conn = ComplianceManager.Properties.Settings.Default.CS_DBConnectionString;
string sql = "SELECT lngCustomerID_pk, txtCustomerName FROM Customers ORDER BY txtCustomerName;";
OleDbConnection connection = new OleDbConnection(conn);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataAdapter.Fill(ds);
connection.Close();
clientComboBox.DataSource = ds.Tables[0];
clientComboBox.DisplayMember = "txtCustomerName";
clientComboBox.ValueMember = "lngCustomerID_pk";
clientComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
clientComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
}
catch (Exception ex)
{
MessageBox.Show("Problem loading client combo box: " + ex.Message);
}
}
The combobox functions as desired: when typing the first few letters of a client, that client can be selected by pressing <TAB> or <ENTER>, the ValueMember and DisplayMember are both changed properly, and the focus is moved to the next control. However, the text from the DisplayMember remains fully highlighted, even while the user types data into another control.
If an item is selected using the dropdown box rather than autocomplete, the appropriate DisplayMember is displayed but does not remain highlighted -- in other words, the desired visual effect.
How do I correct the issue with autocomplete? I have experimented with trapping the tab key on a KeyDown event, but that text remains highlighted.
Thanks,
Paul