Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 尝试将数据源重新绑定到DataGridViewComboxCell时出错?_Vb.net_Datagridview_Datasource_Datagridviewcomboboxcell - Fatal编程技术网

Vb.net 尝试将数据源重新绑定到DataGridViewComboxCell时出错?

Vb.net 尝试将数据源重新绑定到DataGridViewComboxCell时出错?,vb.net,datagridview,datasource,datagridviewcomboboxcell,Vb.net,Datagridview,Datasource,Datagridviewcomboboxcell,我有一个带有两列DataGridViewComboboxColumn的DataGridView。我想使用第一列中的选定项触发第二列中的项按行重新填充 这是我到目前为止的代码。“addlInfoParentCat”标识第一列,currentRow.Cells.Item(1)是我要重新填充的DataGridViewComboxCell。ExtEventAdditionalInfoType是我定义的包含字符串/值对的类型 Private Sub dgvAdditionalInfo_CellValueC

我有一个带有两列DataGridViewComboboxColumn的DataGridView。我想使用第一列中的选定项触发第二列中的项按行重新填充

这是我到目前为止的代码。“addlInfoParentCat”标识第一列,currentRow.Cells.Item(1)是我要重新填充的DataGridViewComboxCell。ExtEventAdditionalInfoType是我定义的包含字符串/值对的类型

Private Sub dgvAdditionalInfo_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvAdditionalInfo.CellValueChanged
    Dim currentCell As DataGridViewCell
    currentCell = Me.dgvAdditionalInfo.CurrentCell
    If Not currentCell Is Nothing Then
        If currentCell.OwningColumn.DataPropertyName = "addlInfoParentCat" Then
            Dim parentTypeID As Integer = currentCell.Value

            Dim currentRow As DataGridViewRow = Me.dgvAdditionalInfo.CurrentRow
            Dim subtypeCell As DataGridViewComboBoxCell = currentRow.Cells.Item(1)

            Dim theChildren As New List(Of ExtEventAdditionalInfoType)

            theChildren = Custom_ExtEventAdditionalInfoType.GetChildrenOfThisParentOrderByTypeName(parentTypeID)
            subtypeCell.DataSource = Nothing
            subtypeCell.DataSource = theChildren
            subtypeCell.DisplayMember = "ExtEventAdditionalInfoTypeDescr"
            subtypeCell.ValueMember = "ID_ExtEventAdditionalInfoType"
        End If
    End If
End Sub
基本上我看到的是,第一次绑定时效果非常好。当我在第一列中选择一个项目时,它会正确地填充第二列中的项目。我可以向DataGridView添加行并重复该过程

当我试图在第二列已经绑定之后更改第一列项目时,问题就出现了。我得到了一系列对话框,其中包含以下内容:

System.ArgumentException:DataGridViewComboBoxCell值无效。

知道为什么会这样吗?提前谢谢

更新CodeByMoonlight的建议似乎有效

我在重新绑定之前清除DataGridViewComboxCell的值:

....

            subtypeCell.DataSource = Nothing
            subtypeCell.Value = Nothing  'here's the change
            subtypeCell.DataSource = theChildren

....

好的,看起来只要你重新修改第一个组合的值,你就会使用来填充第二个组合的绑定和数据源无效,从而导致所有错误。

谢谢你的回答。恐怕我不明白。每次更改第一列中的选择时,我都会得到一个新的孩子列表,并用这个新列表重新绑定第二个组合。绑定无效,但是我重置了它,不是吗?或者我没有正确地进行重新绑定?我认为关键是绑定暂时无效,而不是您随后纠正它。我认为,如果在加载新数据源之前清除第二个组合的值,就可以了。然而,我从Opera Mini发布,所以我现在不能测试这个。