I have two forms.Both having DatagridView.There 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.

Sub GetData(ByVal StrQuery As String)
        If CBMedium.Text <> "" And CBClass.Text <> "" Then
            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
        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

5 Years
Discussion Span
Last Post by Ehtesham Siddiq

When u click on delete button
bind the second grid also with same dataset as firstform

If dr.HasRows Then
                While dr.Read
                    DGVStudRecord.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5))
                    form2.grid.rows.add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5))

                End While
            End If

Thanks mate its working accrding to my requirement.I want to do the same for my Comboboxes.
There are two Comboboxes.I want that the as soon as my second form is shown my comboboxes should have the same selected values that are selected on Form one.Comboboxes on boththe forms contains same Elements as they are populated from Database with the same Query at the Load Event of their respective forms.I have tried to use Object as well as the method u showed to fill second Datagrid.Its still not working.
FrmDeleteClassWiseSmsSetting-second Form
CBClass(on left of =)-Combo on second Form
CBClass(on Right of =)-Combo on First Form

FrmDeleteClassWiseSmsSetting.CBClass.SelectedText = CBClass.SelectedText

Thanks mate im Done with my Issues.This is what im doing at the Load of second form to get my combo selected depending on the selection of Combo on First form.

CBClass.SelectedIndex = FrmSMSMobileNumberSetting.CBClass.SelectedIndex
   CBMedium.SelectedIndex = FrmSMSMobileNumberSetting.CBMedium.SelectedIndex
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.