473,952 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2295
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 PersonCollectio n Find(PersonCrit eria pc)
{
PersonCollectio n foundCollection = new PersonCollectio n();
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*****@glas s-images.com> wrote in message
news:Os******** ******@tk2msftn gp13.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
18243
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 more) fields to filter a query based on selections in two or more fields: All the records with NAME = all the names selected in a list box BETWEEN StartDate and EndDate
6
4645
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 user and I would like to change the whole process. I would like to duplicate the layout of my form... but each field becomes a simple "searching" ListBox. On completing any one search field all the rest are filtered to this value. Subsequent...
0
1505
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 provider requires basic authentication, I would prefer to provide authenication headers with out adding creds directly to the ws proxy class; ie. within code. So i figured I could do via an output filter but I can access the headers. Any ideas or...
3
4014
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 here to filter out the machine accounts so that I get only the NT group objects. public ArrayList GetNTGroups() { DirectoryEntry ntDirectoryGroups = null;
2
1194
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 = String.Concat("D_STAT_CD_C <> '", "N'")
4
11074
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 controls in an unbound form. In order to do so, I moved the content of the controls to an array (that was the easy part) and used the Filter function in order to count the occurence of a each value. However, when I ran the code I got the 450 error...
3
2682
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 report named "Assigned Jobs" shall open by meeting all the following conditions 1) Both Plant list box and supr list box not selected 2) Plant list box selected and supr list box not selected 3) Plant list box not selected but supr list box...
2
4637
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 Select method (a DataRow collection) to make the DataGridView filtering only on those rows? I mean to display only the found rows and after that to select all previous rows back again? I want to use two buttons on my form "Apply Filter" and...
1
2574
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 = x. I could filter this in the database call.. but i'd like to bring back a larger dataset and only make one call to the database for the data retrieval, then in code filter for the id i want, work on that.. and than filter for another id and so...
0
10184
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11385
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10709
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9920
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8289
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7453
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3568
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.