CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Autocomplete in a Combobox

    Either the CHANGE'd event, or the CLICK'ed event, or any other that react.
    MOUSE events as well.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured