Solved

DataGrid Search

Posted on 2006-06-20
4
234 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:gvector1
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:TheAvenger
Comment Utility
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.
0
 

Author Comment

by:gvector1
Comment Utility
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????
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
Comment Utility
You need to go over all rows in the dataview and check if they have the row you need. Something lik:

int index = -1;
for (int i = 0; i < dataView.Count; i++)
{
  if (dataView[i] == rowToFind)
  {
      index = i;
      break;
  }
}

// index contains now the index of the row
0
 

Author Comment

by:gvector1
Comment Utility
That's what I was wondering.  Whether looping through the rows in the table is an efficient method for this.  Thanks for the confimation.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now