Progamtically adding rows into datagridview

Joined
Jun 8, 2006
Messages
5
Programming Experience
Beginner
am new to vb.net programming and have the following question. I am getting data from database into 3 separate listbox. These controls are basically getting populated from separate sql queries.
I want the user to double click on one item per listbox, so that the item automatically populates a pre-defined column of the datagridview (for the current row).
Currently, there is one current row having some default values. I want the user to double click on LISTBOX A so that COLUMNA of the current row gets populated by it.

Similarly double clicking on LISTBOX B and LISTBOX C should add the item into the COLUMN B and COLUMN C for the datagridview( for the current row).
How can this be accomplished. Could someone provide me with some sample code or give some direction.
Thanks,
Raj
 
VB.NET:
    Private Sub ListBox1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick
        'Make sure the user double-clicked an item and not empty space.
        If Me.ListBox1.SelectedItem IsNot Nothing Then
            'Make sure a row is selected.
            If Me.DataGridView1.CurrentRow Is Nothing Then
                Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(0).Cells(0)
            End If

            'Copy the value from the ListBox to the DataGridViewCell.
            Me.DataGridView1.CurrentRow.Cells(0).Value = Me.ListBox1.GetItemText(Me.ListBox1.SelectedItem)
        End If
    End Sub
 
Back
Top