|
-
August 28th, 2009, 10:14 AM
#1
Autocomplete in a Combobox
Hi guys,
today I tried to integrate an autocomplete into my combobox but it does not work. Seems I am forgetting something. Maybe anyone can help me.
I have a collection of items and these items I want to show in a combobox. Additional I want to integrate the autocomplete functionality because the list has 2.000 items.
Here is what I did:
Code:
public class ItemInfo
{
private string _name = String.Empty;
private int _id = 0;
public ItemInfo(int id, string name)
{
this.Id = id;
this.Name = name;
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Id
{
get { return _id; }
set { _id = value; }
}
}
public class ItemInfoCollection : List<ItemInfo>
{
public void Load()
{
this.Add(new ItemInfo(1, "A"));
this.Add(new ItemInfo(2, "AB"));
this.Add(new ItemInfo(3, "ABC"));
this.Add(new ItemInfo(4, "B"));
this.Add(new ItemInfo(5, "BC"));
this.Add(new ItemInfo(6, "BCD"));
}
}
private void Form1_Load(object sender, EventArgs e)
{
ItemInfoCollection collection = new ItemInfoCollection();
collection.Load();
cbxTestSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
cbxTestSearch.AutoCompleteSource = AutoCompleteSource.ListItems;
cbxTestSearch.DropDownStyle = ComboBoxStyle.Simple;
cbxTestSearch.DataSource = collection;
cbxTestSearch.DisplayMember = "Name";
cbxTestSearch.ValueMember = "Id";
}
All seems to work fine. But if I select one entry from the autocomplete list then the autocomplete list close but there is no selected item in the combobox. It is still empty. What do I have forgotten?
Useful or not? Rate my posting. Thanks.
-
August 28th, 2009, 08:56 PM
#2
Re: Autocomplete in a Combobox
Either the CHANGE'd event, or the CLICK'ed event, or any other that react.
MOUSE events as well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|