954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to display only the found detials on a datagrid

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!

shooksy101
Newbie Poster
2 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

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

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

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

Ranx
Light Poster
44 posts since Jul 2007
Reputation Points: 10
Solved Threads: 6
 

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

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: