Hi people, I have created a form that allows me to search customers from a datagrid table which holds the information from the customers table. I use a textbox to enter the phrase to search for and a search button. I can find the records within the datagrid table but it only selects them. I want the datagrid to only display the records found. How I achieve this ?

If RadioButtonName.Checked = True Then
            Me.CustomersTableAdapter.Fill(Me.NorthwindDataSetCustomers.Customers)
            For Each CurrentRow As DataGridViewRow In DataGridView1.Rows
                If CurrentRow.Cells(2).Value.ToString.Contains(TextBoxSearch.Text) Then
                    CurrentRow.Selected = True
               
                End If
            Next
        End If

The code above finds the customers name but it only selects their detials on the datagrid table and i only want those rows found to only be displayed on the datagrid. Can anyone please help?

Thanks!

Recommended Answers

All 3 Replies

In search create table and add the records to new table and then assign that new table to grid as source.

Use the .Select method and set the resulting array of Datarows to be the datasource of your grid

Yes Ranx That will be the good approach.. Thanks :)

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.