DataGrid Selection to Open Form [RESOLVED]
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.
DataGrid Selection to Open Form
I have been programming for 3 months and I am having difficulty with this, however I believe that it should be fairly simplistic.
I can pull up the form I want, but I am having difficulty setting the variables to create the formtext = to StudentID and StudentName in my Dataset
Would it be possible to show an example code, maybe that will help me grasp the concept. I understand variables, maybe I'm making it too hard, but setting variables for the dataset I'm having a hard time with.
I appreciate your patience and help. I have tried to figure this out after your response, but still unable to resolve on my own.
Dim myDataset As DataSet
Dim intStudentID As Integer
Dim strStudentLName As String
Dim strStudentFName As String
Dim frmMessage As New String
frmMessage.Text = (intStudent - strStudentLName, strStudentFName)
Thank you in advance for any help.
DataGrid Selection to Open Form [RESOLVED]
Thank you for your offer to help. This has finally been resolved with help from others.
The following code is what worked for me:
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
'The code below will open a second form when a user clicks on
'the first column of the datagrid of the first form
'and the form title text will show the record #- LName, FName
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 Form2()
Prog.MdiParent = Me.MdiParent
Prog.Label1.Text = ComboBox1.Text
Prog.Label2.Text = TextBox1.Text
Prog.Text = DataGrid1.Item(hti.Row, hti.Column) & _
"- " & DataGrid1.Item(hti.Row, 1) & ", " & _
DataGrid1.Item(hti.Row, 2)
Prog.Show()
End If
Cursor.Current = System.Windows.Forms.Cursors.Default
End If
End Sub
Hope this can be of help to someone else.
Thank you again for you offer of help.