In WinForms application, I have a combobox which I am trying to populate with values based on user input. For example if the user types m
it should show him all the values that starts with the letter m
, but I dont want to add all the values in the beginning because there are a lot of values.
To achieve this, I created an event textchanged
and when a user inputs for example the letter m
my program goes to my database and adds all the values with the letter m
to the combobox.
The problem that I think that the combobox first sees if it should autocomplete (suggest) values and only after that it adds the values.
How can I make it add the values first or make the combobox check again if it should suggest values?
Here is my code:
private void comboBox1_TextChanged(object sender, EventArgs e)
{
comboBox1.Items.Clear();
for (int i = 0; i < MilkProducts.Length; i++)
{
if (MilkProducts[i].StartsWith(comboBox1.Text))
{
comboBox1.Items.Add(MilkProducts[i]);
}
}
}