[RESOLVED] DataGridView searching
I've loaded a txt file in a DataGridView called DataGridView1.
I've also got a search function which shows the row including that what you searched.
When I search something it always is in a column called: "szName".
The column in before "szName" is called "//dwID".
How can I get the bit of text in column "//dwID" of the selected row in a TextBox (TextBox1)
Thanks in Advance
Re: DataGridView searching
try this:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim matchRowdwID = (From dgvRow In DataGridView1.Rows _
Let r = DirectCast(dgvRow, DataGridViewRow) _
Where Not r.IsNewRow AndAlso r.Cells("szName").Value.ToString = TextBox1.Text _
Select r.Cells("dwID").Value).ToArray
If matchRowdwID.Count > 0 Then MsgBox(matchRowdwID.First.ToString)
End Sub
Re: DataGridView searching
I'm using this code:
Code:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim matchRowdwID = (From dgvRow In DataGridView1.Rows Let r = DirectCast(dgvRow, DataGridViewRow) Where Not (r.IsNewRow AndAlso r.Cells("szName").Value.ToString = TextBox1.Text) Select r.Cells("//dwID").Value).ToArray
If matchRowdwID.Count > 0 Then MsgBox(matchRowdwID.First.ToString)
End Sub
But it always shows the first match in //dwID
Re: DataGridView searching
Quote:
Originally Posted by
TooLongName
But it always shows the first match in //dwID
i tested it, so i know it works.
do you mean there is more than one match returned from the query?
Re: DataGridView searching
"//dwID" is also not a valid name for a column
Re: DataGridView searching
I made a stupid mistake :sick:
Code:
Where Not r.IsNewRow AndAlso r.Cells("szName").Value.ToString = TextBox1.Text _
The part where the searchterm is in isn't called TextBox1.Text but sSearchTerms...
Thanks for the help paul :)