.netvb.netdata-bindingdatatabledatagridviewcomboboxcell

DataMember Error when firing CellValueChanged


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


Solution

  • 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