Universal search to data view/table/grid
Dear all,
I created a winform that display an item master in a DataGridView, bound with a DataView. Let's just say it has columns/fields
- item_id
- item_name
- item_description
I wanted to make a single text box that will be searched in all fields. So if any field in a row contains searched item, it will be displayed.
My current idea is to create a DataView with RowFilter contains all rows such
Code:
myDataView.RowFilter = "item_id LIKE '%" & Me.txtSearch.Text & "%' OR " & _
"item_name LIKE '%" & Me.txtSearch.Text & "%' OR " & _
"item_desc LIKE '%" & Me.txtSearch.Text & "%'"
Is there any smarter way to do this?
I'm afraid this code will cause a big slowdown for a larger dataset.....
Thanks in advanced.
Yoachan
Re: Universal search to data view/table/grid
From my personal experience I would say this is pretty good way of doing it. I use the same method to filter datasets of 10,000+
You may want to consider your actual search string though. Firstly can item_id contain text characters? Then you shouldn't use the single quotes around them. When searching an Id field (usually a unique ID), it is rather odd to use a LIKE. If you put 1 in the text box, do you really want all records with 1 in the id number? Is that useful?
In my experience, its better to provide a entry field for the user to enter the id number (if they know it), or if not, a single field to search name and description.
Re: Universal search to data view/table/grid
@Enrico: Thanks for your reply.
Quote:
Originally Posted by
enrico1982
From my personal experience I would say this is pretty good way of doing it. I use the same method to filter datasets of 10,000+
It's a relief then :)
Quote:
Originally Posted by
enrico1982
You may want to consider your actual search string though. Firstly can item_id contain text characters? Then you shouldn't use the single quotes around them.
Yes, the item_id is a string and contain text characters :)
Quote:
Originally Posted by
enrico1982
When searching an Id field (usually a unique ID), it is rather odd to use a LIKE. If you put 1 in the text box, do you really want all records with 1 in the id number? Is that useful?
Thank you for your suggestions, putting more limit in the search will be much better approach :)
Quote:
Originally Posted by
enrico1982
In my experience, its better to provide a entry field for the user to enter the id number (if they know it), or if not, a single field to search name and description.
Separate text fields was my first approach.
But in several forms (such item master lookup), I want to make as simple lookup form as possible, with as few navigation as needed.
But for more complex report, your approach will be much better.
Again, thanks :)