|
-
Feb 10th, 2012, 08:51 AM
#1
Thread Starter
New Member
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
-
Feb 10th, 2012, 09:29 AM
#2
Hyperactive Member
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.
Rico
Using: VB.net & MS SQL
-
Feb 10th, 2012, 10:49 AM
#3
Thread Starter
New Member
Re: Universal search to data view/table/grid
@Enrico: Thanks for your reply.
 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 
 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 
 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 
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|