Click here to Skip to main content
15,889,830 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hello ,

I am unable to load a Datagridview combobox column on a Keypress event. When the user enters a character , I'll fetch all the entries starting from that character (From the Database). During the same event i need to Suggest append all the list items. It works only when i move out of the cell and then come back.This is because the data is yet to be loaded on keypress event .

I have set the Auto Complete properties. I am working on VB2005 Express edition.

One more observation - It's works for a Normal combo box but not for a Datagridview Combobox column.

Is there any solution where i can load the Datagridview combobox column and suggest append after user presses a single character ?

Regards,
Rohit
Posted

1 solution

Finally got what i wanted.Here is the Working Code in VB.net
Add a Datagridview with the first column as DatagridviewComboboxColumn
Paste the code and then Type 'a' to get all the list items in SuggestAppend format.


Public class Form1
Dim ComboMedType As ComboBox

Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCellAddress.X > 0 Then Exit Sub

ComboMedType = CType(e.Control, ComboBox)

If (ComboMedType IsNot Nothing) Then
'Change Style To DropDown, To Allow For Data Entry
ComboMedType.DropDownStyle = ComboBoxStyle.DropDown
ComboMedType.AutoCompleteMode = AutoCompleteMode.SuggestAppend
ComboMedType.AutoCompleteSource = AutoCompleteSource.ListItems
End If

AddHandler ComboMedType.KeyDown, AddressOf ComboMedType_KeyDown
End Sub

'In this event, 10 items are added into the combobox(A0,A1 etc)
Private Sub ComboMedType_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)

'Load only when characters are Pressed
If e.KeyValue >= 65 And e.KeyValue <= 90 Then

Dim I As Short

While I < 10

Dim stDrugName As String = "A" & I

ComboMedType.Items.Add(Trim(stDrugName))
I += 1
End While

End If
End Sub

End class
 
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