我已经阅读了DataGridView Cascading/Dependent ComboBox Columns的帖子,并使用datagridview和2列组合框进行了相同的项目,其中第二个组合框通过选择第一个组合框进行了过滤。 我很想有可能在第二个组合框中取消选择,如果用户选择错误,第二个组合框可以清除选择...
这里有我使用的代码: 1)第一个组合框为FASE 2)第二个组合框是SOTTOFASE
Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim grid = DirectCast(sender, DataGridView)
If (grid.CurrentCell.ColumnIndex = 1) Then 'State column
Dim combo = DirectCast(e.Control, DataGridViewComboBoxEditingControl)
If (grid.CurrentRow.Cells(0).Value IsNot DBNull.Value) Then
Dim dvStates = New DataView(MondoDBDataSet1.Tables("SOTTOFASI"), $"n_fase = '{grid.CurrentRow.Cells(0).Value}'", "n_fase ASC", DataViewRowState.CurrentRows)
combo.DataSource = dvStates
combo.ValueMember = "n_sottofase"
combo.DisplayMember = "sottofase"
Else
combo.DataSource = Nothing
End If
End If
End Sub
感谢帮助!
这是3个步骤的图像:
解决方案: 我已实现事件KeyUp,并在按下按钮“ del”时将单元格值设置为“ dbnull”
Private Sub DataGridView1_KeyUp(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyUp
If GetAsyncKeyState(Keys.Delete) Then
Dim CellCombo As DataGridViewComboBoxCell
If DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value <> -1 Then
CellCombo = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1)
CellCombo.Value = DBNull.Value
End If
End If
End Sub