PC Review


Reply
Thread Tools Rate Thread

BindingList<T> and .FindAll()

 
 
Merk
Guest
Posts: n/a
 
      11th Dec 2006
I need to show users a list of "Person" attributes in a grid. I currently
have a custom "Person" class that mostly has a bunch of string properties
(firstName, lastName, etc).

While I want to have a collection of [a few hundred] Person objects behind
the scenes, I want for only a specific subset to appear in the grid at any
given time. The subset would be determined by rules such as (ID Number
Between 100 and 130, or lastName begins with "SCH"), and the user will
control which rule is in effect (i.e., user can specify which subset appears
in the grid).

How would you go about implementing the above? I went in the direction of
the following, but it seems overly complicated.

So I was thinking to have two collections - one for all Person objects
(lstAll), and another collection for the currently viewed subset
(lstCurrent). My intention was to have lstAll be an instance of the generic
..List<T> - but for lstCurrent to be a BindingList<T> instance (and bound to
the grid). I wanted to somehow use the FindAll method of lstAll (a List<T>)
to get references to the requisite Person objects into lstCurrent (a
BindingList<T>). But I'd prefer to do this without looping if there is a
faster way. Speed is important especially as the size of lstAll grows.

I'd appreciate any recommendations for how to proceed. I'm feeling "in a bit
over my head" at this point.

Thanks!


 
Reply With Quote
 
 
 
 
Ben Voigt
Guest
Posts: n/a
 
      11th Dec 2006

"Merk" <(E-Mail Removed)> wrote in message
news:OhT$(E-Mail Removed)...
>I need to show users a list of "Person" attributes in a grid. I currently
>have a custom "Person" class that mostly has a bunch of string properties
>(firstName, lastName, etc).
>
> While I want to have a collection of [a few hundred] Person objects behind
> the scenes, I want for only a specific subset to appear in the grid at any
> given time. The subset would be determined by rules such as (ID Number
> Between 100 and 130, or lastName begins with "SCH"), and the user will
> control which rule is in effect (i.e., user can specify which subset
> appears in the grid).


Is the number of rules small? You could use a IBindingList<> for each
subset, and a IBindingList<> for the main list. Then, subscribe each subset
list to the main list ListChanged event. When an item is added or removed
from the main list, test if it meets the criteria for the subset, then
add/remove it from the subset. This will make your iterative search
operations tend to be proportional to the subset size instead of the full
list length.

Also consider using a sorted list, linked list, or hashtable and
implementing IBindingList<> on top instead of using the default
BindingList<>.

>
> How would you go about implementing the above? I went in the direction of
> the following, but it seems overly complicated.
>
> So I was thinking to have two collections - one for all Person objects
> (lstAll), and another collection for the currently viewed subset
> (lstCurrent). My intention was to have lstAll be an instance of the
> generic .List<T> - but for lstCurrent to be a BindingList<T> instance (and
> bound to the grid). I wanted to somehow use the FindAll method of lstAll
> (a List<T>) to get references to the requisite Person objects into
> lstCurrent (a BindingList<T>). But I'd prefer to do this without looping
> if there is a faster way. Speed is important especially as the size of
> lstAll grows.
>
> I'd appreciate any recommendations for how to proceed. I'm feeling "in a
> bit over my head" at this point.
>
> Thanks!
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findall question tshad Microsoft C# .NET 2 20th Jan 2010 08:26 PM
FindAll. Linq. shapper Microsoft C# .NET 4 29th Aug 2008 08:11 PM
Re: Using Array.FindAll Göran Andersson Microsoft VB .NET 2 1st Aug 2008 02:05 AM
BindingList<T> and .FindAll() Merk Microsoft C# .NET 1 11th Dec 2006 09:17 PM
DirectorySearcher.FindAll() =?Utf-8?B?QW5kcmV3MTI0?= Microsoft ASP .NET 0 11th Jul 2004 10:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 AM.