Changing values from columns according to DataGrid

2019-08-27 01:30发布

问题:

I have the following DataGridViewComboBoxColumn which is generated in execution time and inserted in a DataGridView:

    Public Sub GenerateCol()
        Try
            Col.DataSource = LoadData()
            Col.DisplayMember = "code"
            Col.ValueMember = "code"
            Col.Name = "col2"
            Col.HeaderText = "Column 2"
            Col.DataPropertyName = "col2"
            Col.SortMode = DataGridViewColumnSortMode.Automatic
            dgv.Columns.Insert(15, Col)
        Catch ex As Exception
            MsgBox("ERROR: " & vbCrLf & ex.Message, MsgBoxStyle.Information)
        End Try
    End Sub 

And this is the method which loads values into tha ComboBox Cells:

Private Function LoadData() As DataTable
    Try
        dt = sd.RunService("Service", DSResult) 'executes a sql string
        Return dt.Tables(0)
    Catch ex As Exception
        MsgBox("No Data" & vbCrLf & ex.Message, MsgBoxStyle.Information)
    End Try
End Function 

Return output:

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

However, I want to know which events I must use to change the values of two DataGridViewNumericColumn. One of these dgvNumericColumn must take the value of the datatable exposed, according to the value (code) displayed in the ComboBoxCell and the date selected. The other column, must take that value and another value of a third column (I have to multiply those values).

I was thinking in SelectedIndexChanged event but I'm still working on it. It actually does nothing:

Private Sub Col_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim SelectedMon As Object
    Dim SelectedDiv = CType(Col.Selected, String)

    SelectedMon = dt.Tables(0).Columns("value")
    col_Mon.Value = col_Nom * SelectedMon
    col_valmon.Value = SelectedMon

End Sub

EDIT: I created a new question about the CellValueChanged Event. It now fires but with problems. Thanks in advance