Partial searching of a datagridview

  • Thread starter Thread starter Robert Bravery
  • Start date Start date
R

Robert Bravery

Hi all,

I am looking for a way to create partial serching of a datagridview. SO that
as a user would type in a textbox, the position of the row pointer in the
grid would change incrementaly as the user types
so that (searing in 'name' column) if they type "B" the pointer would dind
the start of names beginnig with 'B', then type 'o', and the pointer moves
to the start of 'Bo' and so on.

Can some one point me in the right direction.

Thanks
Robert
 
Robert,

There are a number of things that are going to influence the answer
here.

The first is, are you using a consistent data source? Are you always
binding to a datatable/dataview with the same schema, or are you sometimes
binding to a list or something of that nature? If the underlying data is
going to change, or not consistent (or you have abstracted it out so you
don't have access to the original structure), then you have to cycle through
the rows/cells in a brute-force manner. Brute-force is required if the data
is not ordered according to your search criteria (in this example, if the
data is not sorted on the name, then you can't really search quickly).

If you have access to the underlying data, then it's a little easier,
since you can use the methods native to the data container to search, and
then change your selection appropriately. For example, if you are bound to
a data table, then you can call the Select method to figure out which row
corresponds to the search criteria (and then select it).

However, this is only the case if the view on the data matches the
underlying data. If you allow the user to sort the data, then you can't
access the datatable, but rather, you have to access the view that the grid
is bound to, and then search on that.
 

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

Back
Top