Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for an incremental search grid
Message
From
11/07/2004 01:04:02
 
 
To
10/07/2004 14:23:53
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00923011
Message ID:
00923089
Views:
29
Hi, Tony,

I can't answer the last question, as I don't own MM.

However, you can implement basic incremental searching with the .NET datagrid by doing something like the following:

1) Let's say you have a data grid that's bound to the default view for DtCustomers. The grid shows each customer name, customer number, address, etc.

2) You have a textbox where the user can enter a partial customer name. As the user types a letter, you want the reposition the grid based on any 'hit' on the customer name.

3) In the textchanged event of the textbox, you can grab the text for the textbox, and pass the text to a function called IncrSearch

4) In IncrSearch, you can scan through the rows in the defaultview for DtCustomers until you get a 'hit', like so...
// must grab the binding manager for the datagrid, as we'll want to highlight the row 
// for the 'match'

BindingManagerBase bMgr = dataGrid.BindingContext[dataGrid.DataSource,dataGrid.DataMember];

// now scan through the rows

for(int iRowCtr=0;iRowCtr<DtCustomers.DefaultView.Count;iRowCtr++)
   if(DtCustomers.DefaultView[iRowCtr]["AcctName"].ToString().ToUpper().IndexOf(cSearchText.Trim().ToUpper(),0)>=0)  
      	bMgr.Position = iRowCtr;       // match...so set the position
Note that I'm forcing everything to upper case on both sides, to make it case-insensitive.

Two other notes:

- I set up a find and find next - in that case, I pass a flag to my search function, for whether to start at position zero, or at the current row + 1 (based on whatever the binding manager is reporting for the current position

- If you want to 'filter' the grid so that the only customers that show are those that match the search text, you can use the RowFilter property for the defaultview. You can check the on-line help for examples of syntax for RowFilter.

Hope this gives you some ideas.
Kevin
Previous
Reply
Map
View

Click here to load this message in the networking platform