The following method initializes the combo box with the auto-complete functionality.
public void init_box()
{
AutoCompleteStringCollection ax = new AutoCompleteStringCollection();
if (File.Exists("List.txt"))
{
using (StreamReader reader = new StreamReader("List.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
ax.Add(line);
}
}
}
comboBox1.AutoCompleteCustomSource = ax;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
}
next, this method is called on the mouse click event of the combo box.
private void comboBox1_MouseClick(object sender, MouseEventArgs e)
{
init_box();
}
No comments:
Post a Comment