Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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

   'using the datatable to fill the rest of the columns
         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)
             
             'retreiving the selected index
            index = c.SelectedIndex
        End If

 End Sub


Thank you, regards.

[Edit - Fixed pre tag, spelling, and grammar]
Posted
Updated 6-Mar-12 4:51am
v3

1 solution

Your question is not clear what exactly is wrong ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900