Searching text in datagridview

G

Guest

Hi

Well what i'm trying to do is search text in a datagridview, i've seen
similar code around in other posts or forums, i'm implementing this by using
a Textbox, and the code in the TextChanged event, so when the user keeps
typing, the datagridview must refresh itself showing only the results that
contain the text written so far.

I've seen this in two ways.....checking the text in the rows one by one....
and the other way is using a query, like..

string query = "SELECT * FROM Table WHERE title=" + txtSearch.Text;

and after that execute the query and update the datagridview, something like
that.... but which way to do it has better performance??

mmm another thing, the table has less than 1000 rows.. so maybe it won't
even be a significant difference in time, but still, i'd like to know other
opinions about which way results in a faster, better and easier way to do it
:)

Thanks in advance
 
F

ForrestPhoto

The question isn't really which option will make your code run faster;
you want to search the data-grid by enumerating the rows and avoid
querying the database over and over to keep pressure off the database.

Also, you probably want to look into "delayed event handling" so that
you don't check a thousand rows after every keystroke.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top