Link to home
Start Free TrialLog in
Avatar of gvector1
gvector1

asked on

DataGrid Search

What is the best way to search a datagrid?
I know of 2 ways:
Loop through the rows checking the values for the one that I am searching for,
Use a dataview.find method.

I would like to use a dataview method, but it requires that I sort the dataview.  If I sort the dataview, won't it return the wrong row index of my search field.  Ex:

If my datagrid lists appointments for a doctor and I am searching for patient number 3 which is 5th on the list.  If I sort the dataview by patient number, won't that give me the wrong index compared to my datagrid.  My datagrid is showing my appointments in order by appointment time.  Another thing, what if I don't know the names of my columns at the time I am trying to search a dataview???????????????

Any help is appreciated,
Kendal
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

If you have a DataTable as the source of the view, you can search by using the Select method. Its something like:

dataTable.Select ("PatientNumber = " + patientNumber);

This returns an array of DataRows which meet the condition. You could dynamically create the condition string if you don't know the column name at design time.
Avatar of gvector1
gvector1

ASKER

But I need to know the row #s containing the values entered for the search so that I can actually select those rows within the datagrid.  How can I go about doing that????
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's what I was wondering.  Whether looping through the rows in the table is an efficient method for this.  Thanks for the confimation.