Changing values from columns according to DataGridViewComboBoxCell

…衆ロ難τιáo~ 提交于 2019-12-24 19:47:15

问题


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

来源:https://stackoverflow.com/questions/48998580/changing-values-from-columns-according-to-datagridviewcomboboxcell

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