hi friends...
i want to search a record from a datagridview with an input box...
Can anyone help me plz...
It's 4 my project ...
Need help plzzzz...

Recommended Answers

All 27 Replies

So you need to type the parameter in a input box to filter the Grid?

Are you using VS 2003 or VS 2005?

Database SQL or Access?

hi friends...
i want to search a record from a datagridview with an input box...
Can anyone help me plz...
It's 4 my project ...
Need help plzzzz...

Ok, what's the problem? Assume you want your users to enter a term in a textbox then you will search for that term. Is that correct? Give a little more info on the issue and what you need.

VS 2005 et database Access

You could loop through the rows in the datagridview ? Or maybe re-query the datasource?

Dim intcount As Integer = 0
For Each Row As DataGridViewRow In DataGridView1.Rows
If DataGridView1.Rows(intcount).Cells(0).Value = "StringSearch" Then
'Do Something
intcount +=1
End If
Next Row

Do you want to search a particuar column from the DB or just any text in the Grid?

Text in the grid... I think they mean... ?

You Can use something like this using DataView

Dim dv As New DataView(ds.Tables(0))
dv.RowFilter = "FirstName = '" & TextBox1.Text & "'"
DataGrid1.DataSource = dv

You can replace the Textbox2.text to the value returned from the inputbox.

hi thanks it works...
the search works, it select only the fullrows containing the firstname i type in the input box but all the other data disappear.
i don't want it to disapppear, i want it to be in the datagrid..
help me plz

i want to search a particular rows in the datagrid..
for example Any columns containing the data the user want to type, i want only the the data to be selected

for ex the user may want to serach all female, then only the rows female will b selected

Private Function Find(ByVal StrSearchString As String) As Boolean

        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect

        Dim intcount As Integer = 0
        For Each Row As DataGridViewRow In DataGridView1.Rows
            If DataGridView1.Rows(intcount).Cells(0).Value.ToString = StrSearchString Then
                DataGridView1.Rows(intcount).Selected = True                
                    Find = True
                Exit Function
            End If
            intcount += 1
        Next Row
        Find = False
    End Function

I think the logic from Triss would do that. Let me know.

Hey Friends but where should i put the private function find
coz am using a button with an input box..
And wat should i put in the button search ,coz, there is nothing there except the input box...

Copy paste code... open form designer drop a button and a textbox on it, double click button then enter...

Call Find(textbox1.text)


Hey Triss
the button search doesn't do anything whevever i click it...


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call Find(TextBox1.Text)
    End Sub

hey i have already copy n paste the function on the form and put the code call find to the button but it doesn't works. i have enter something in the textbox 2 n then press the button but nothing happens.
Help Me plzzz

Attach the project I will have a look if you want.

Hi triss can u help me how can i search name that starts with the letter F in a datagridview.
For example if i type F in the inputbox i got every name started with the letter F.

Hi I would either use the filter options or requery your datasource.

Hey guys I have been closely watching your threads regarding searching a record in a datagrid as I have the same problem as Geetajilo.

I can easily search for something in a datagrid by entering a field into a textbox and pressing the search button. This works fine when the record is already in the datagrid, but however how can you retrieve a record from the database and place it in the datagrid.??

Thanks for your time

You can do it by quering it based on a column name. So you have to write a backend query to bind your search to the GRID.

For Each CurrentRow As DataGridViewRow In DgCustomerList.Rows
            If CurrentRow.Cells(3).Value.ToString.Contains(TxtSearch.Text) Then
                CurrentRow.Selected = True
                DgCustomerList.Rows(0).Selected = True
            End If
    End Sub

Welcome anandkumarrs6.

We appreciate your help. Have you ever noticed that the current thread is three years old? Please do not resurrect old threads and have a look at forum rules. Please read before posting - http://www.daniweb.com/forums/thread78223.html

Thread Closed.

commented: Yes! +20


plz help me to sold my problem... I have a database(access) and all I want is to view all the records of the person that l've searching.. using textbox and view it in the DataGrid. I using vb6 and my database is access. what is the best code for my problem? plz........

Please start a new thread for your question. Please ensure you post in the correct forum. Yours is a VB6 question. This is VB.net.

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.