Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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 在验证同一列和同一行中以前的DataGridViewTextBoxCell后,为设置新的DataGridViewComboxCell_Vb.net_Winforms_Datagridview_Datagridviewcomboboxcell_Datagridviewtextboxcell - Fatal编程技术网

Vb.net 在验证同一列和同一行中以前的DataGridViewTextBoxCell后,为设置新的DataGridViewComboxCell

Vb.net 在验证同一列和同一行中以前的DataGridViewTextBoxCell后,为设置新的DataGridViewComboxCell,vb.net,winforms,datagridview,datagridviewcomboboxcell,datagridviewtextboxcell,Vb.net,Winforms,Datagridview,Datagridviewcomboboxcell,Datagridviewtextboxcell,我有这个DataGridView,它有一个DataGridViewTextBoxColumn,用户可以在其中键入一个数字,在他键入数字后,我执行搜索以查找该数字下以前的记录 我想显示这些记录,这样用户就可以选择其中一个,或者保持键入的值,这意味着他想创建一个新记录 为此,我想在用户完成键入后,用这些选项替换datagridviewcomboxcell的每个datagridviewcontextboxcell 但是,当我尝试在System.Windows.Forms.dll中置换此替换时,它引发了

我有这个
DataGridView
,它有一个
DataGridViewTextBoxColumn
,用户可以在其中键入一个数字,在他键入数字后,我执行搜索以查找该数字下以前的记录

我想显示这些记录,这样用户就可以选择其中一个,或者保持键入的值,这意味着他想创建一个新记录

为此,我想在用户完成键入后,用这些选项替换
datagridviewcomboxcell
的每个
datagridviewcontextboxcell

但是,当我尝试在System.Windows.Forms.dll中置换此替换时,它引发了此异常:“System.invalidoOperationException”。其他信息:该操作无效,因为它导致对函数SetCurrentCellAddressCore的重新输入调用。

这是我的代码(我已经尝试处理
CellLeave
而不是
CellValidated
):


非常感谢

我已经将有问题的语句放入Lambda sub via.BeginInvoke中,这解决了问题,只是我不知道为什么

谁能给我解释一下它的原理吗?谢谢大家!

Private Sub DataGridViewDebitos_CellValidated(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridViewDebitos.CellValidated
    DataGridViewDebitos.EndEdit(DataGridViewDataErrorContexts.Commit)
    If e.ColumnIndex = ColumnDebito.Index Then
        Dim cellDebito = DataGridViewDebitos.Rows(e.RowIndex).Cells(ColumnDebito.Index)
        Dim numDebito = String.Concat(If(cellDebito.Value, "").ToString.Where(Function(c) Char.IsLetterOrDigit(c)))
        If TypeOf cellDebito Is DataGridViewTextBoxCell AndAlso numDebito.Length >= 3 Then
            Dim prcsa As New List(Of JObject) 'In real version, prcsa is populated by an external function, but it doesn't affect the result
            Dim j = New JObject
            j.SetProperty("id", 0)
            j.SetProperty("nome", cellDebito.Value)
            prcsa.Insert(0, j) 'This option is always present, it allows user to keep simply what was typed
            'Exception hapens here
            DataGridViewDebitos.BeginInvoke(
                Sub()
                    DataGridViewDebitos(cellDebito.ColumnIndex, cellDebito.RowIndex) =
                        New DataGridViewComboBoxCell With {
                        .DataSource = prcsa,
                        .DisplayMember = "nome",
                        .FlatStyle = FlatStyle.Flat,
                        .ValueMember = "id",
                        .Value = prcsa(0)("id")}
                End Sub)
        End If
    End If
End Sub
Private Sub DataGridViewDebitos_CellValidated(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridViewDebitos.CellValidated
    DataGridViewDebitos.EndEdit(DataGridViewDataErrorContexts.Commit)
    If e.ColumnIndex = ColumnDebito.Index Then
        Dim cellDebito = DataGridViewDebitos.Rows(e.RowIndex).Cells(ColumnDebito.Index)
        Dim numDebito = String.Concat(If(cellDebito.Value, "").ToString.Where(Function(c) Char.IsLetterOrDigit(c)))
        If TypeOf cellDebito Is DataGridViewTextBoxCell AndAlso numDebito.Length >= 3 Then
            Dim prcsa As New List(Of JObject) 'In real version, prcsa is populated by an external function, but it doesn't affect the result
            Dim j = New JObject
            j.SetProperty("id", 0)
            j.SetProperty("nome", cellDebito.Value)
            prcsa.Insert(0, j) 'This option is always present, it allows user to keep simply what was typed
            'Exception hapens here
            DataGridViewDebitos.BeginInvoke(
                Sub()
                    DataGridViewDebitos(cellDebito.ColumnIndex, cellDebito.RowIndex) =
                        New DataGridViewComboBoxCell With {
                        .DataSource = prcsa,
                        .DisplayMember = "nome",
                        .FlatStyle = FlatStyle.Flat,
                        .ValueMember = "id",
                        .Value = prcsa(0)("id")}
                End Sub)
        End If
    End If
End Sub