Auto Complete For a TextBox Control in DataGridView
In This article, I will explain the code snippet for Auto Complete a TextBox Control in DataGridView . It may be useful for learning the concept of TextBox Control in DataGridView.
Hi,
A Small Article Which Show you how to Show Tool tip for a Column Index of 1 in DataGridView
Before Going To the Main Function(s) we need to do some Small Manipulations to GridView
1. Grid View should have Enable Editing to True
2. Grid View Should have EditControlShowing Event
After doing that through Design now comes to code part
Declare a Variable Gobally
Private scAutoComplete As New AutoCompleteStringCollection
in Form_Load Event am Calling a Function Called bind Grid and let's have a look how bind Grid Function
Private Sub bindGrid()
DataGridView1.DataSource = getTable() ' To get Data Table for the Grid View
setAutoComplete()
End Sub
Private Sub setAutoComplete()
For i As Integer = 1 To 5
scAutoComplete.Add("Praveen " & CStr(i)) ' For Sample i added my name here you can load values from database
Next
End Sub
so in Form Load we binded data to Grid View and We gave values to Auto Complete Extender also
Now see the Code for Gridview Editing Controls Showing
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCell.ColumnIndex = 1 AndAlso TypeOf e.Control Is TextBox Then ' Checking Whether the Editing Control Column Index is 1 or not if 1 Then Enabling Auto Complete Extender
With DirectCast(e.Control, TextBox)
.AutoCompleteCustomSource = scAutoComplete
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.CustomSource
End With
Else ' we are not Enabling Auto Complete Extendar
With DirectCast(e.Control, TextBox)
.AutoCompleteMode = AutoCompleteMode.None
End With
End If
End Sub
if you want to show for more than a column then take another AutoCompleteStringCollection Variable and assign to that autocompletecustomsource
hope this will help some one

Hi Kastriot,
for that you need to add Key Down event for the textbox and in that Event get the value from the db or any location and add to autocomplete extender object.