我有一个包含datagridviewcomboboxcolumn的datagridview,我在该列上启用了编辑。只要没有为列设置datapropertyname,它就可以工作。
当设置了datapropertyname并在组合框中输入时,系统会按应该的方式建议该项,但当按ENTER键时,先前选择的项将再次被选中。
而当按enter后未设置datapropertyname名称时,则选择建议项。
我启用编辑的代码:
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发布于 2016-01-11 19:34:34
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 Subhttps://stackoverflow.com/questions/6042848
复制相似问题