Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am create windows application using c# 2010, I am using data grid view for this application in my grid view 2 columns, I am using combo box but how to create autocomplete for my combo boxes.


any one give me some ideas

What I have tried:

I am create windows application using c# 2010, I am using data grid view for this application in my grid view 2 columns, I am using combo box but how to create autocomplete for my combo boxes.
Posted
Updated 29-May-16 19:50pm
v2

 
Share this answer
 
In windows form application you can use 'AutoCompleteMode of combobox to accomplish your task, just follow the steps
1. Create one Windows Application and add DataGridView from toolbox to design.
2. Now create two DataGridViewComboBoxColumns and add them to the DataGridView:
C#
public void ComboList1()
        {
            DataGridViewComboBoxColumn combo1 = new DataGridViewComboBoxColumn();
            combo1.HeaderText = "fruit";
            combo1.Items.Add("Apple");
            combo1.Items.Add("Grapes");
            combo1.Items.Add("Orange");
            combo1.Items.Add("Mango");
            dataGridView1.Columns.Add(combo1);
        } 

call above method in form constructor
Now Click on DataGridView and generate EditingControlShowing event and write the folllowing code in it:
C#
if (e.Control is DataGridViewComboBoxEditingControl)
            {
                ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
                ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
                ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
            }

The AutoCompleteMode and AutoCompleteSource properties create a ComboBox that automatically completes input strings by comparing the prefix being entered to the prefixes of all strings in a maintained source.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900