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

To Search a record in datagridview

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

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 

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

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

Are you using VS 2003 or VS 2005?

Database SQL or Access?

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 
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.

vcombstlh
Newbie Poster
1 post since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

VS 2005 et database Access

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 

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

Triss
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

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

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

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

Triss
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

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.

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

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

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 

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

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 
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
Triss
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

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

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

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

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 

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

Call Find(textbox1.text)

Done.

Triss
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

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

y

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call Find(TextBox1.Text)
    End Sub
Triss
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

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

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 

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

Triss
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

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.

geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You