Hello Experts,

I wanted to filter a data where when I click on a DataGrid in FormA, FormB with DataGrid will only show the corresponding data. The passing Key is CustomerID. 
To be more clear:
Form Customer with DataGrid1(which display all Customer list in CustTbl)
CustID  CustName
1        ABC 
2        DEF
When I click on the DataGrid1 in FormCustomer, it will open a new Form Invoice(with DataGrid) where it will only display the information related to the Custmer,where the Primary Key is the CustID.
I get the Form Invoice open but my Datagrid display all records.

Thanks all.
5 Years
Discussion Span
Last Post by M.Waqas Aslam

Inline Code Example Here
I had added this code but my DataGrid now appear empty

Dim dvFilter As DataView = Nothing

    If TypeOf dgv.DataSource Is DataView Then
        dvFilter = CType(dgv.DataSource, DataView)
    ElseIf TypeOf dgv.DataSource Is DataTable Then
        dvFilter = CType(dgv.DataSource, DataTable).DefaultView
    End If
    If Job_NOTextBox.TextLength > 0 Then
        dvFilter.RowFilter = ("select * from Invoive_Trans WHERE Job_NO LIKE '*" & Job_NOTextBox.Text & "*'")
        'dvFilter.RowFilter = ""  **this gives me error=Object reference not set to an instance, so I commented it
    End If
    dgv.DataSource = dvFilter

what i understand is that you have two forms , having datagrid , when you click datagrid1 on form one or select any customer form the grid then the second grid will populate with all related data of selected customer , if yes then you can do like this .

'use double click event of your datagrid and use this code

'now use this code at the load event of your 2nd form.

dim con as new sqlconnection("your connection string")
dim da as new sqldataadapter("select * from tableCustomerInfo where customerid = "+frm1.datagridview1.item("customerid",frm1.datagridview1.currentrow.index).value.tostring,con
dim dt as new datatable
datagridview1.datasource= dt

hope this will solve your prob.


This topic has been dead for over six months. 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.