My form has a textBox and i want to add autocomplete while typing.
My autocomplete values are loaded dynamically via a json api.
I applied the “update” function on the “TextChanged” Event of the textBox.
Everytime it is triggered, the autocomplete opens for 0.5 sec and the textBox’s value changes to the first autocomplete entry. After that the autocomplete menu disappears.
I cannot choose any suggestions manuelly…
How to fix?
onload Event:
AutoCompleteStringCollection colValues = new AutoCompleteStringCollection();
private void StellenUebersicht_Load(object sender, EventArgs e)
{
TextBox textBoxExample = textBox1;
textBoxExample.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBoxExample.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxExample.AutoCompleteCustomSource = colValues;
doAutoCompleteListExample();
}
doAutoCompleteListExample():
private void doAutoCompleteListExample()
{
if (textBox1.Text.Length >= 1)
{
string w = Web.get("MY JSON API URL");
JObject o = JObject.Parse(w);
List<string> ac = new List<string>();
foreach (JObject item in o["items"])
{
string name = item["name"].ToString();
ac.Add(name);
}
colValues.AddRange(ac.ToArray());
}
}
i fixed it.
Solution:
change
to