VB.NET-Datagridview组合框筛选器和空值

VB.NET-Datagridview组合框筛选器和空值,vb.net,datagridview,Vb.net,Datagridview,我读过这篇文章,我用datagridview和2列combobox做了相同的项目,其中第二个combobox是通过选择第一个combobox来过滤的。 我想有一个可能性做取消选择在第二个组合框,如果用户选择错误第二个组合框可以清除选择 以下是我使用的代码: 1) 第一个组合框是FASE 2) 第二个组合框是Sottobase Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEdi

我读过这篇文章,我用datagridview和2列combobox做了相同的项目,其中第二个combobox是通过选择第一个combobox来过滤的。 我想有一个可能性做取消选择在第二个组合框,如果用户选择错误第二个组合框可以清除选择

以下是我使用的代码: 1) 第一个组合框是FASE 2) 第二个组合框是Sottobase

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个步骤的图像:

解决方案: 我已经实现了事件键控,并在按下按钮“del”时将单元格值设置为“dbnull”

Private子DataGridView1\u KeyUp(发送方作为对象,e作为KeyEventArgs)处理DataGridView1.KeyUp
如果GetAsyncKeyState(Keys.Delete),则
Dim CellCombo作为DataGridViewComboBoxCell
如果DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value-1,则
CellCombo=DataGridView1.Rows(DataGridView1.CurrentRow.Index)。单元格(1)
CellCombo.Value=DBNull.Value
如果结束
如果结束
端接头

您的datagridview的图像将帮助我们更好地了解您正在尝试做什么。我已加载了一个图像。。谢谢
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