激活CellValueChanged时DataMember错误

问题描述 投票:0回答:2

继我的前question 关于根据comboboxcolumncells改变柱细胞的值,现在我有以下问题。我的事件触发,但是我在DataBindings行上收到以下错误消息:无法链接DataSource中的属性或函数“value”。参数名称: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
...

提前致谢

.net vb.net data-binding datatable datagridviewcomboboxcell
2个回答
1
投票

澄清你的dt是什么?在这里你说明它有一个“价值”属性

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

在这里,您声明有一个Tables属性,并且在“0” - 索引表中有一个“值”。

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

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


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
© www.soinside.com 2019 - 2024. All rights reserved.