473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Filter Collection

Hello all,
I have a custom collection that I am using to fill a DropDown list that
I need to filter out items based on another dropdown list. My problem is
the actual filter in the collection. I can add a filter sub to the
collection code but I am not sure how to find which property to use. Say
if my custom object is like this:
Person
ID
FirstName
LastName

And then I create a collection of Persons (using CollectionBase) how
would I be able to tell my filter sub which field I want to filter by
and how would I not lose all the records in the collection as I do not
want to have to hit the db again to get back the rest of the data that
was filtered out? Also this collection is being used for both ASP.NET
and Winforms so I need to do this in the collection not on the GUI side.

-Stanley
Nov 19 '05 #1
1 2270
Well, ur 2nd dilemma is simple. In your function, create a new collection
and populate it with matches. There are a couple ways to solve your first
problem, but I'll suggest the Criteria approach used in the CSLA.Net
(http://www.lhotka.net/ArticleIndex.a...ea=CSLA%20.NET)

I'd create a Criteria object which can have the properties you want to
filter on...something like:

public class PersonCriteria
{
private int id;
private string firstName;
priate string lastName;

//appropriate constructors and properties here
}
I'd then do:

PersonCriteria pc = new PersonCriteria(0, null, "blah");

and I'd add the following function to the collection

public PersonCollection Find(PersonCriteria pc)
{
PersonCollection foundCollection = new PersonCollection();
foreach (Person p in this.List)
{
if ((pc.Id = 0 || pc.Id = p.Id) && (pc.FirstName == null ||
pc.FirstName == p.FirstName) && ...)
{
foundCollection.Add(p);
}
}
return foundCollection;
}

Also, check out:
http://weblogs.asp.net/plip/articles/111127.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Stanley" <st*****@glass-images.com> wrote in message
news:Os**************@tk2msftngp13.phx.gbl...
Hello all,
I have a custom collection that I am using to fill a DropDown list that
I need to filter out items based on another dropdown list. My problem is
the actual filter in the collection. I can add a filter sub to the
collection code but I am not sure how to find which property to use. Say
if my custom object is like this:
Person
ID
FirstName
LastName

And then I create a collection of Persons (using CollectionBase) how
would I be able to tell my filter sub which field I want to filter by
and how would I not lose all the records in the collection as I do not
want to have to hit the db again to get back the rest of the data that
was filtered out? Also this collection is being used for both ASP.NET
and Winforms so I need to do this in the collection not on the GUI side.

-Stanley

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: arthur-e | last post by:
I can filter a query for a report on a field of a subform BUT now.... I'd like to be able to select more than one item in a multi-list box to select all the records. ALSO to use two fields (or...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
0
by: KBC | last post by:
Is there any way to access HTTP Headers within an output filter? I can access HttpContext.Current but that returns an HttpRequest object which has an read-only collection. The web service...
3
by: Prasad Karunakaran | last post by:
I have the following C# code to enumerate the list of groups in a domain using ADSI. The problem is if the domain contains machine accounts ($) it get those accounts too. Can somebody help me...
2
by: vvenk | last post by:
Hello: I have the following code: Dim lsFilter As String = Nothing Select Case rblStatus.SelectedItem.Value Case "S" lsFilter = String.Concat("D_STAT_CD_C = '", "N'") Case "R" lsFilter =...
4
by: hadardo | last post by:
Hello all. Let me start by saying that I don't use VBA so often, so I ask for your forgivness if my questions is somewhat silly. I'm trying to find if a user typed the same value in two or more...
3
by: josejomonm | last post by:
I am having a list box where I will select the Plants (Plant-1 or Plant-2 Etc.) or leave blank for selecting all plants. Another list box in the same form where the supervisors list is provided. A...
2
by: Paul | last post by:
Hi all, I have a DataTable and a DataGridView that is using it as a datasource. I'm using the DataTable.Select method and I can find some rows. Is it now possible, somehow to use the result of the...
1
by: jvcoach23 | last post by:
I have a custom class QBank with a public property called QBankID. I populate the ilist(to QBank). when the iList is populated, is there a way i can filter on the QBankID property for where it =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.