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...

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.

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

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

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)

Done.

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

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
            Else
                DgCustomerList.Rows(0).Selected = True
            End If
        Next
    End Sub

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

PLZ HELP ME.. I WANT TO SEARCH A EMPLOYEE'S RECORD TO MY DATABASE ADODC IN SEARCH BOTTON(TEXT1) AND ONLY THE RECORDS OF EMPLOYEE VIEW IN THE DataGrid.. WHAT IS THE CODE FOR IT.? PLZZZZZZZZ.....

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.

Edited 3 Years Ago by Reverend Jim

This article has been dead for over six months. Start a new discussion instead.