Passing value from another form to fill datagridview

Here' what I am trying to achieve...I had a form(frmMain) having a Customer/Orders structure..The data are displaying properly using the dtagridview.I want to display the details by having another form(frmChoose) by which a user will choose for the name of the company he wishes to display details with.This chosen value will be passed to the control(lblCompany) of frmMain and supossedly display the order details based on that company chosen by the user...My ordeal now was how can I fill the datagridview using this setup.Had tried to pass this using the this code but apparently to no avail.

Private Sub dgvPatients_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvPatients.CellClick
DisplayCurrentRowData()
End Sub

Private Sub DisplayCurrentRowData()
Dim RowData As String = String.Empty
For Each c As DataGridViewCell In dgvPatients.CurrentRow.Cells
RowData += c.Value.ToString()
Next
frmMain.lblCompany.Text = RowData 'text will be passed to the frmMain label control)
End sub

Hope you guide me on this one...


Answer this question

Passing value from another form to fill datagridview

  • Stuart Holdstock

    Try filtering the bindingsource that you use as a datasource for your DataGridView. With one line of code, I think you can get the functionality you're looking for. Try the following line of code in the text changed event for your label.

    YourBindingSource.Filter = String.Format("CompanyNameDataColumn = '{0}'", lblCompany.Text)

    Good luck,

    Tony



  • Kofoed

    Great One my friend....Cheers...

  • Passing value from another form to fill datagridview