DataMember Error when firing CellValueChanged

心已入冬 提交于 2019-12-11 16:16:23

问题


Following my anterior question about changing values on column cells according a comboboxcolumncells, now I have the following problem. My event fires, but I get the following error message on the DataBindings line: can't link the property or function "value" in DataSource. Parameter Name: dataMember. Aside of that, the values of the other columns didn't changed. What should I do in this case?

   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's structure: This datatable is charged into the comboboxcell, which displays the "code" and the value I want to write on the other columns cells of the row (Col_1 and Col_2), is the "value" associated to that code:

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

Thanks in advance


回答1:


Clarify what is your dt? Here you stating that there is a "value" property in it

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

And here you state that there is a Tables property, and inside the "0"-index table there is a "value".

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

I think you should use dt.Tables(0) or something like it as datasource




回答2:


Finally I didn't need to use DataBindings. Instead, I only assigned values to the fields of the columns col_2 and col_3. This went more simpler than I thought :

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


来源:https://stackoverflow.com/questions/49051322/datamember-error-when-firing-cellvaluechanged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!