Datagrid Selected Item to Open Form

ettropics

Newcomer
Joined
Feb 20, 2003
Messages
8
FORM1 has a datagrid populated by way of a dataset/dataadapter

FORM 2 is an INPUT FORM (for adding new student records) and is also used as a POPULATED FORM (showing populated student records) containing textboxes, comboboxes, checkboxes and datagrids.

I would like to be able to open FORM1
SELECT a record from the datagrid
and have it open up FORM2 with the StudentID and StudentName in the Form Text. And have all the objects populated with the pertinent information for that specific selection.



Any help would be greatly appreciated.
 
The code below open a second form when the user click on the first column of the datagrid of the first form.

Visual Basic:
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
        Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
        hti = DataGrid1.HitTest(e.X, e.Y)
        If hti.Type = System.Windows.Forms.DataGrid.HitTestType.Cell Then
            If hti.Column = 0 Then
                Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
                    Dim Prog As New Form4()
                    Prog.MdiParent = Me.MdiParent
                    prog.Label1.Text = ComboBox1.Text
                    prog.Label2.Text = TextBox1.Text
                    prog.Label4.text = DataGrid1.Item(hti.Row, hti.Column)
                    prog.Label5.text = DataGrid1.Item(hti.Row, 1)
                    If Not DataGrid1.Item(hti.Row, 2) Is DBNull.Value Then
                        prog.Label6.text = DataGrid1.Item(hti.Row, 2)
                    End If
                    Prog.Show()
                End If
                Cursor.Current = System.Windows.Forms.Cursors.Default
            End If
        End If
    End Sub
 
Last edited by a moderator:
Datagrid Selected Item to Open Form [RESOLVED]

Gregory: Thank you, thank you. This is exactly what I was looking for. With a little tweaking this did exactly what I wanted it to do.

One day I hope to be able to help others as I have been helped. I am early in my programming career, 3 months in and I thank you for being there and your help.
 
Back
Top