[英]Datagridview DatagridviewComboboxColumn Editing DataBound
我有一个带有datagridviewcomboboxcolumn的datagridview,在其上启用了编辑。 只要没有为列设置datapropertyname,此方法就起作用。
当设置了datapropertyname且我在组合框中键入内容时,系统会建议该项目,但按ENTER键时,将再次选择先前选择的项目。
当在按回车键后未设置数据属性名称时,将选择建议的项目。
我的启用编辑的代码:
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If e.Control.GetType Is GetType(DataGridViewComboBoxEditingControl) Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
cb.DropDownStyle = ComboBoxStyle.DropDown
End If
End If
End Sub
Private Sub grdReceiving_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles grdReceiving.EditingControlShowing
If e.Control.GetType Is GetType(DataGridViewComboBoxEditingControl) Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
cb.DropDownStyle = ComboBoxStyle.DropDown
End If
End If
End Sub
Private Sub grdReceiving_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles grdReceiving.CellValidating
Select Case e.ColumnIndex
Case 4
Dim comboBoxColumn As DataGridViewComboBoxColumn = grdReceiving.Columns(4)
If (e.ColumnIndex = comboBoxColumn.DisplayIndex) Then
If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
comboBoxColumn.Items.Add(e.FormattedValue)
End If
End If
grdReceiving.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = e.FormattedValue
Case 5
Dim comboBoxColumn As DataGridViewComboBoxColumn = grdReceiving.Columns(5)
If (e.ColumnIndex = comboBoxColumn.DisplayIndex) Then
If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
comboBoxColumn.Items.Add(e.FormattedValue)
End If
End If
grdReceiving.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = e.FormattedValue
Case 6
Dim comboBoxColumn As DataGridViewComboBoxColumn = grdReceiving.Columns(6)
If (e.ColumnIndex = comboBoxColumn.DisplayIndex) Then
If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
comboBoxColumn.Items.Add(e.FormattedValue)
End If
End If
grdReceiving.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = e.FormattedValue
End Select
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.