Click here to Skip to main content
16,015,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm trying to write a function that gets the text of a textbox and checks it with all values of a datagridview,
The problem i face is that the comparison is true and the column value in datagridview is "John Smith" and the textbox.text is "Smith" when I trace it I can see it, but the code does not work and the row visibility is still true.
Here is the code:::

VB
For Each row As DataGridViewRow In dgFirst.Rows
                If (row.Cells.Item("Column2").Value.ToString().Contains(TextBox1.Text)) Then
                    row.Visible = False
                End If
            Next


A similar code to it is working properly:

VB
For Each row As DataGridViewRow In dgFirst.SelectedRows
                dgFirst.Rows.Item(row.Index).Visible = False
            Next


What I have tried:

I'm still working on it, and yet i couldn't find the answer.

(2nd update)
It's like the line below reutrns a false anser:

(row.Cells.Item("Column2").Value.ToString().Contains(TextBox1.Text))
Posted
Updated 14-Jun-16 22:25pm
v2
Comments
CHill60 15-Jun-16 4:19am    
When you are debugging does the code step into the if-statement and attempt to action row.Visible=False or does it just skip to the Next?
Have you tried replacing row.Visible=False with dgFirst.Rows.Item(row.Index).Visible = False?
m.r.m.40 15-Jun-16 4:24am    
No, it doesn't step into the if statement.

It's like the line below reutrns a false anser:

(row.Cells.Item("Column2").Value.ToString().Contains(TextBox1.Text))
m.r.m.40 15-Jun-16 4:30am    
Interesting!!!

It got solved by closing and re-opening the VS. :/
CHill60 15-Jun-16 4:40am    
That is bizarre! But VS can be sometimes ;-)
It might be worth using TextBox1.Text.Trim() in the comparison though and you might want to consider the case that the user enters the text in e.g. SMITH, smith, Smith are all different
m.r.m.40 15-Jun-16 4:57am    
Good consideration, Thanks.

Thanks for helping.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900