How to use an object to travel data from one form to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SEhtesham
    New Member
    • Aug 2011
    • 45

    How to use an object to travel data from one form to another

    Hi,
    I have two forms.Both having DatagridView.Th ere are two comboboxes to filter the record from Database and fill in Datagridview.My requirement is when all the data is populated in DataGrid after selecting the comboboxes and when the user clicks on Delete.
    The comboboxes and Datagrid on second form should have the same values as that was on first form.The names of my Comboboxes and Datagridview are same on both the forms
    Below is the code my Datagrid view getting populated in First Form.
    Code:
     Sub GetData(ByVal StrQuery As String)
            If CBMedium.Text <> "" And CBClass.Text <> "" Then
                DGVStudRecord.Rows.Clear()
                con = DBConnect()
                cmd = New SqlCommand(StrQuery, con)
                dr = cmd.ExecuteReader
                If dr.HasRows Then
                    While dr.Read
                      
                        DGVStudRecord.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5))
                    End While
                End If
                con.Close()
            
            End If
        End Sub
    Please suggest how can i populate my datagrid in second form by using the Data populated in Datagrid of Firrt Form
  • basenxuser
    New Member
    • Sep 2011
    • 2

    #2
    Hi,

    I think creating a singleton class will help you hold values across forms. Check singleton pattern under creational pattern in design patterns. If need a online help, go to dofactory site, there it is explained nicely by GOF

    Comment

    • SEhtesham
      New Member
      • Aug 2011
      • 45

      #3
      Thanks mate for your reply.I think i was not able to explain u what i wanted.I have got a simpler way to do it.I just want that some data that is populated on form1 should be displayed in form2 as well.
      This was my grid for Form1.I want the same data also on form2 when user clicks a certain button on form1.So i can simply assign these values to Datagrid in form2.
      Code:
        DGVStudRecord.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5))
      form2.DGVOnForm2.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5))
      Frnds i think this is the simplest way to do it.
      Last edited by SEhtesham; Sep 23 '11, 11:22 AM. Reason: Correction

      Comment

      Working...