触发 CellValueChanged 时出现 DataMember 错误

DataMember Error when firing CellValueChanged

之前 question 关于根据 comboboxcolumncells 更改列单元格的值,现在我遇到了以下问题。我的事件触发,但我在 DataBindings 行收到以下错误消息:can't link the 属性 or function "value" in DataSource.参数名称:dataMember。除此之外,其他列的值没有改变。在这种情况下我该怎么办?

   Private Sub dgv_CellValueChanged(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgv.CellValueChanged

        Dim r As Integer = e.RowIndex
        Dim c As Integer = e.ColumnIndex

        Try
            If r > -1 Then 
                If c = 15 Then
                    dgv.DataBindings.Add("Text", dt, "value", False, DataSourceUpdateMode.OnPropertyChanged) 'I wanted to overwrite cells with the value associated with the code of the comboboxcell

                    Dim col_div_cell_value As Object = dt.Tables(0).Columns("value")

                    dgv.CurrentRow.Cells("col_1").Value = col_div_cell_value.Value()
                    dgv.CurrentRow.Cells("col_2").Value = (col_div_cell_value * col_3)

                End If
            End If

        Catch ex As Exception
            MsgBox("ERROR: " & ex.Message, MsgBoxStyle.Information)
        End Try

    End Sub

dt的结构:这个datatable被充进了comboboxcell,里面显示了"code"和我要写的值该行的其他列单元格(Col_1 和 Col_2)是与该代码关联的 "value"

code  |  date | value
---------------------
A       12/06   100
B       12/06   200
...

提前致谢

说清楚你的dt是什么? 在这里你说里面有一个 "value" 属性

dgv.DataBindings.Add("Text", dt, "value", False, DataSourceUpdateMode.OnPropertyChanged)

这里你说有一个表 属性,在“0”-index table 里面有一个 "value".

Dim col_div_cell_value As Object = dt.Tables(0).Columns("value")

我认为你应该使用 dt.Tables(0) 或类似的东西作为数据源

终于不用DataBindings了。相反,我只为 col_2col_3 列的字段赋值。这比我想象的要简单:

Private Sub dgv_CellValueChanged(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgvBlotter.CellValueChanged
    Dim r As Integer = e.RowIndex
    Dim c As Integer = e.ColumnIndex

    Try
        If r > -1 Then 
            If c = 15 Then

                Dim flag As Double = dgv.CurrentRow.Cells("col2").Value 'name of comboboxcolumn
                Dim nuevovalor As Object = flag
                Dim nominal As Double = dgv.CurrentRow.Cells("col_3").Value

                dgv.CurrentRow.Cells("col_1").Value() = nuevovalor
                dgv.CurrentRow.Cells("col_2").Value() = (nuevovalor * nominal)

            End If
        End If
    Catch ex As Exception
        MsgBox("ERROR: " & ex.Message, MsgBoxStyle.Information)
    End Try

End Sub