ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Create AutoComplete ComboBox in a DataGridView Using C#

AutoCBODTGFig.3In this tutorial, I will teach you how to create an AutoComplete ComboBox in a DataGridView using C#.net. With this method, you can make the ComboBox become an Auto-Suggest and Append in the DataGridView. This method is very helpful because you don’t need to drop down and select the data in the ComboBox, all you have to do is type the first letter that you want to select. It will just automatically suggest and append the data of your selection.

 

So, Let’s get started.

 

Open Microsoft Visual Studio and create a new windows form application for C#. After that, add a DataGridView in the form and it will look like this.

AutoCBODTGFig.1

Double-click the form and do the following codes for creating and adding items in the list control of a ComboBox on the first load of the form.

 //Declaring variable as new DataGridViewComboBoxColumn
 //That represents a column in the datagridview.
 DataGridViewComboBoxColumn cbo = new DataGridViewComboBoxColumn();
 //'Putting a list of items in the combobox.
 cbo.Items.Add("Janobe");
 cbo.Items.Add("Janry");
 cbo.Items.Add("John Craig");
 cbo.Items.Add("Jeanniebe");
 cbo.Items.Add("Joken"); 
 //Adding a combobox in the column on the datagridview.
 dataGridView1.Columns.Add(cbo);

Go back to the Design Views, click the DataGridView and go to the properties. In the properties, hit the lightning symbol and double-click the event handler named EditingControlShowing.

AutoCBODTGFig.2

After that, do the codes in the method for the AutoComplete ComboBox in the DataGridView.

 //e represent the editing control in the datagridview
 //the condition is, if the type of e is combobox then set your code for autocomplete
 if (e.Control is ComboBox)
 { 
 DataGridViewComboBoxEditingControl cbo = e.Control as DataGridViewComboBoxEditingControl;
 //set the dropdown style of a combobox
 cbo.DropDownStyle = ComboBoxStyle.DropDown;
 //set the propety of a combobox to autocomplete mode.
 cbo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
 cbo.AutoCompleteSource = AutoCompleteSource.ListItems;
 }

Output:

AutoCBODTGFig.3

For all students who need a programmer for your thesis system or anyone who needs a source code in any a programming languages. You can contact me @ :

 

 

Email – jannopalacios@gmail.com
Mobile No. – 09305235027 – TNT

 

Download Source Code

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!