Vb.net - Datagridview Combobox专栏 [英] Vb.net - Datagridview Combobox column
问题描述
您好,
我无法在Keypress事件中加载Datagridview组合框列。当用户输入一个字符时,我将从该字符(从数据库)开始获取所有条目。在同一事件中,我需要建议附加所有列表项。它只有当我离开单元格然后再回来时才有效。这是因为数据尚未加载到按键事件上。
我设置了自动完整的属性。我正在研究VB2005 Express版。
还有一个观察 - 它适用于普通组合框,但不适用于Datagridview Combobox列。
有没有解决方案,我可以加载Datagridview组合框列并在用户按下单个字符后建议追加?
问候,
Rohit
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
推荐答案
终于得到了我想要的东西。这是VB.net中的工作代码
添加Datagridview,第一列为DatagridviewComboboxColumn
粘贴代码,然后输入'a'以获取所有列表项SuggestAppend格式。
公共类Form1
Dim ComboMedType作为ComboBox
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs)Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCellAddress.X> 0然后退出Sub
ComboMedType = CType(e.Control,ComboBox)
If(ComboMedType IsNot没什么)然后
'将样式更改为DropDown,允许数据输入
ComboMedType.DropDownStyle = ComboBoxStyle.DropDown
ComboMedType.AutoCompleteMode = AutoCompleteMode .SuggestAppend
ComboMedType.AutoCompleteSource = AutoCompleteSource.ListItems
结束如果
AddHandler ComboMedType.KeyDown,AddressOf ComboMedType_KeyDown
结束次级
'在这个事件中,10个项目被添加到组合框中(A0,A1等)
Private Sub ComboMedType_KeyDown(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyEventArgs)
'仅在字符被按下时加载
如果e.KeyValue> = 65并且e.KeyValue< = 90那么
Dim I As Short
虽然我< 10
Dim stDrugName As String =A&I
ComboMedType.Items.Add(Trim (stDrugName))
我+ = 1
结束时
结束如果
结束子
结束课
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
这篇关于Vb.net - Datagridview Combobox专栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!