private void comboKeyPressed()
        {
            cboAuthor.DroppedDown = true;

            object[] originalList = (object[])cboAuthor.Tag;
            if (originalList == null)
            {
                // backup original list
                originalList = new object[cboAuthor.Items.Count];
                cboAuthor.Items.CopyTo(originalList, 0);
                cboAuthor.Tag = originalList;
            }

            // prepare list of matching items
            string s = cboAuthor.Text.ToLower();
            IEnumerable<object> newList = originalList;
            if (s.Length > 0)
            {
                newList = originalList.Where(item => item.ToString().ToLower().Contains(s));
            }

            // clear list (loop through it, otherwise the cursor would move to the beginning of the textbox...)
            while (cboAuthor.Items.Count > 0)
            {
                cboAuthor.Items.RemoveAt(0);
              //  cboAuthor.Items.Remove(cboAuthor.SelectedIndex);
            }

            // re-set list
            cboAuthor.Items.AddRange(newList.ToArray());
        }

i got error in cboAuthor.Items.RemoveAt(0) on key press data in combobox is binded by database

One option, modify the datasource and refill the combobox. Specific details of other options will depend on the objects in the datasource.

Are you trying to remove the items while iterting the collection? This will give you the runtime error...you can probably create a temporary list and modify and then re-assign.

put it in an events. for example.

private void button1_Click(object sender, EventArgs e)
{
    CboAuthor.Items.RemoveAt(0);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.