I have a datagridview with one of its column as TextBox. I wrote a function to populate values from database and suggest values to autocomplete the text. I achieved it, and then I started coding to make a column auto increment (Sr.No) , so I wrote some more lines of code and changed some properties and all of a sudden the textbox stopped auto-completing. Now I tried every possible step to make it work but failed. I dont know what is the property that I changed affected this. I am putting my code here, please help
This is the code for Editingcontrolshowing event...
Private Sub DataGridView2_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView2.EditingControlShowing
DataGridView2.BeginEdit(True)
Dim autoText As TextBox = TryCast(e.Control, TextBox)
If autoText IsNot Nothing Then
autoText.AutoCompleteMode = AutoCompleteMode.SuggestAppend
autoText.AutoCompleteCustomSource = AutoCompleteLoad()
autoText.AutoCompleteSource = AutoCompleteSource.CustomSource
End If
End Sub
This is the autocomplete function where I loaded values...
Public Function AutoCompleteLoad() As AutoCompleteStringCollection
Dim str As AutoCompleteStringCollection = New AutoCompleteStringCollection()
Dim ConnectionString As SqlConnection = New SqlConnection("data source=ADMIN-PC\SQLEXPRESS; database=billdev;Trusted_Connection=yes;")
Dim strSQL As String = "SELECT * from bill;"
Dim SQLcommand As New SqlCommand(strSQL, ConnectionString)
ConnectionString.Open()
Dim reader As SqlDataReader
reader = SQLcommand.ExecuteReader()
While reader.Read()
str.Add(reader.Item(1))
End While
Return str
End Function
This is the extra code I added before it stopped working, but I think this doesn't make any difference
Private Sub DataGridView2_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView2.RowPrePaint
If e.RowIndex >= 0 Then
Me.DataGridView2.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
End If
End Sub
I found the solution.
I tried changing every property of the datagridview randomly. And finally got to the point.
It is the WRAP
property of the column itself.