Hey guys,
I have a datagridview that has some columns. The first column is a combobox so when I select a value from the combobox, I want other columns to fill with the appropriate value depending on the first selection. How can I do this in vb.net?
The purpose of this is to create an invoice application.
Thank you for your help.
So this what I came up with after some time. Can anybody help me fix it and make it more stable? Because I know it is wrong, but I cannot fix it.
First I selected a value in the combobox, then this is what will happen after that:
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Try
If e.ColumnIndex = 0 Then
DataGridView1.Item(2, e.RowIndex).Value = dt.Rows.Item(index).Item("Description")
DataGridView1.Item(3, e.RowIndex).Value = dt.Rows.Item(index).Item("Listprice")
ElseIf e.ColumnIndex = 1 Then
DataGridView1.Item(4, e.RowIndex).Value = CDec(DataGridView1.Item(1, e.RowIndex).Value) * CDec(DataGridView1.Item(3, e.RowIndex).Value)
ElseIf e.ColumnIndex = 3 Then
DataGridView1.Item(4, e.RowIndex).Value = CDec(DataGridView1.Item(1, e.RowIndex).Value) * CDec(DataGridView1.Item(3, e.RowIndex).Value)
End If
Catch
End Try
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then
Dim comboControl As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)
comboControl.DropDownStyle = ComboBoxStyle.DropDown
Dim c As ComboBox = CType(e.Control, ComboBox)
index = c.SelectedIndex
End If
End Sub
Thank you, regards.
[Edit - Fixed pre tag, spelling, and grammar]