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.

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 & "*'")
        'Else
        '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
frm2.open()

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

dim con as new sqlconnection("your connection string")
con.open()
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
da.fill(dt)
datagridview1.datasource= dt
con.close()

hope this will solve your prob.

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.