Results 1 to 5 of 5

Thread: DataGrid Selection to Open Form [RESOLVED]

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    12

    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.
    Last edited by ettropics; Mar 6th, 2003 at 10:38 PM.

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Simply you have to get the ID from form1 and pass it to form2 and select the records in form2 based on that ID. You can define a variable class and use it to share the variables between forms. Other ways are possible too.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    12

    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.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I tell you the concept here:

    1. Either define a varibale class to hold the values you want to pass to form2 or public properties in form1 that contains those values.
    2. Define a dataadapter and a dataset in form1 and populate your datagrid.
    3. Place some code to catch row selection of your datagrid and there assing those values (studentnumber, first name, last name..) to the properties and then show form2
    4. In form2 add a dataadapter with parametrized select query (the parameter would be for example the student number that you are trying to show its records data)
    5. In form2 load event read those properties and pass it to form2.text and also to the parameter of the dataadapter then fill your dataset.

    If you still have difficulty with it sent me your application so i wil help you writing the code.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    12

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width