[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Peter Larsen [CPH]

10/27/2008 4:23:00 PM

Hi,

I use a List<object> as datasource to a DataGridView class.

The datasource class looks like this:
public class DataList : List<DataListItem>
{
...
}

Is it possible to "remove" or omit some entities from the list temporary ??

Lets say i have 100 items in the list and they are sorted after their
colors.
The user then choose to remove some of the colors from the list.
What i want to do, is to omit some of the items from the view (temporary
hiding) without removing them from the list. Is that posible ??

Thank you in advance.
BR
Peter


8 Answers

Bill D

10/27/2008 4:57:00 PM

0

Since you have a custom class, why not create a method that returns the
generic list of objects which can provide the list for the data bind. This
could then create a new copy of your source list filtered by whatever you
needed and return that to the calling method. Depending on the version of the
framework you are using you could do this through a foreacch loop, or much
cleaner using LINQ.

"Peter Larsen [CPH]" wrote:

> Hi,
>
> I use a List<object> as datasource to a DataGridView class.
>
> The datasource class looks like this:
> public class DataList : List<DataListItem>
> {
> ...
> }
>
> Is it possible to "remove" or omit some entities from the list temporary ??
>
> Lets say i have 100 items in the list and they are sorted after their
> colors.
> The user then choose to remove some of the colors from the list.
> What i want to do, is to omit some of the items from the view (temporary
> hiding) without removing them from the list. Is that posible ??
>
> Thank you in advance.
> BR
> Peter
>
>
>

Peter Larsen [CPH]

10/28/2008 8:38:00 AM

0

Not a bad idea - it would work - easy and simple solution.
I'm using .Net 3,5 and LinQ in my code.

I still think there must be another way to do this - something that includes
an interface and override an enumeration method.
It must be using an enumerator when getting the data from the datasource. I
just don't know which.

/Peter


"wdudek" <wdudek@newsgroup.nospam> wrote in message
news:471593BB-AE41-4BF5-AF7A-904641735EED@microsoft.com...
> Since you have a custom class, why not create a method that returns the
> generic list of objects which can provide the list for the data bind. This
> could then create a new copy of your source list filtered by whatever you
> needed and return that to the calling method. Depending on the version of
> the
> framework you are using you could do this through a foreacch loop, or much
> cleaner using LINQ.
>


abilwd

10/28/2008 11:46:00 AM

0

I think you may consider storing the ?°removed?± status of each DataListItem
in the DataList class, and over-writing DataList?¯s GetEnumerator function.
In the function, we go through each element of the list, check its
?°removed?± status, and ?°yield?± the element if its status is not
?°removed?±.
"Peter Larsen [CPH]" <PeterLarsen@community.nospam> wrote in message
news:uSKEDiNOJHA.240@TK2MSFTNGP03.phx.gbl...
> Not a bad idea - it would work - easy and simple solution.
> I'm using .Net 3,5 and LinQ in my code.
>
> I still think there must be another way to do this - something that
> includes an interface and override an enumeration method.
> It must be using an enumerator when getting the data from the datasource.
> I just don't know which.
>
> /Peter
>
>
> "wdudek" <wdudek@newsgroup.nospam> wrote in message
> news:471593BB-AE41-4BF5-AF7A-904641735EED@microsoft.com...
>> Since you have a custom class, why not create a method that returns the
>> generic list of objects which can provide the list for the data bind.
>> This
>> could then create a new copy of your source list filtered by whatever you
>> needed and return that to the calling method. Depending on the version of
>> the
>> framework you are using you could do this through a foreacch loop, or
>> much
>> cleaner using LINQ.
>>
>
>

Bill D

10/28/2008 1:38:00 PM

0

The later reply sounds like it would provide a means to do this, my concern
however would be that you are then creating code that could be confusing to
later developers. When they databind to the list and don't get all of the
records they may not realize at first that there is some sort of filtering
going on. By explicitly calling a method whose name implies the results may
be filtered you do risk this issue.

"Peter Larsen [CPH]" wrote:

> Not a bad idea - it would work - easy and simple solution.
> I'm using .Net 3,5 and LinQ in my code.
>
> I still think there must be another way to do this - something that includes
> an interface and override an enumeration method.
> It must be using an enumerator when getting the data from the datasource. I
> just don't know which.
>
> /Peter
>
>
> "wdudek" <wdudek@newsgroup.nospam> wrote in message
> news:471593BB-AE41-4BF5-AF7A-904641735EED@microsoft.com...
> > Since you have a custom class, why not create a method that returns the
> > generic list of objects which can provide the list for the data bind. This
> > could then create a new copy of your source list filtered by whatever you
> > needed and return that to the calling method. Depending on the version of
> > the
> > framework you are using you could do this through a foreacch loop, or much
> > cleaner using LINQ.
> >
>
>
>

Peter Larsen [CPH]

10/29/2008 8:38:00 AM

0

It is something similar to this, i'm talking about.
Thanks.

"abilwd" <abilwd@hotmail.com> wrote in message
news:%23MceOLPOJHA.4092@TK2MSFTNGP06.phx.gbl...
>I think you may consider storing the ¡°removed¡± status of each
>DataListItem in the DataList class, and over-writing DataList¡¯s
>GetEnumerator function. In the function, we go through each element of the
>list, check its ¡°removed¡± status, and ¡°yield¡± the element if its status
>is not ¡°removed¡±.
> "Peter Larsen [CPH]" <PeterLarsen@community.nospam> wrote in message
> news:uSKEDiNOJHA.240@TK2MSFTNGP03.phx.gbl...
>> Not a bad idea - it would work - easy and simple solution.
>> I'm using .Net 3,5 and LinQ in my code.
>>


Peter Larsen [CPH]

10/29/2008 8:46:00 AM

0

What i want is to allow the user to select a filter in a ContextMenu - its
not a permanent filter.
The default is that there is no filter applied.

I have found a class called "BindingSource" which contains a filter
propertry (haven't tried the filter property yet), but i think this is what
i need.
The class is placed in between the datasource and the viewer.

/Peter


"wdudek" <wdudek@newsgroup.nospam> wrote in message
news:33440317-C16E-4019-8F37-B541E13B0C20@microsoft.com...
> The later reply sounds like it would provide a means to do this, my
> concern
> however would be that you are then creating code that could be confusing
> to
> later developers. When they databind to the list and don't get all of the
> records they may not realize at first that there is some sort of filtering
> going on. By explicitly calling a method whose name implies the results
> may
> be filtered you do risk this issue.
>


Bill D

10/29/2008 1:33:00 PM

0

Yes I understand what you are trying to do, and using a class in between the
data source and the viewer sounds like a good solution. My point was that
embedding the filtering logic in the enumerator of a class could be confusing
to someone 5 years down the road who has to work on the same code and isn't
sure why they are not getting all of the results whent he enumerator is used.

Bill

"Peter Larsen [CPH]" wrote:

> What i want is to allow the user to select a filter in a ContextMenu - its
> not a permanent filter.
> The default is that there is no filter applied.
>
> I have found a class called "BindingSource" which contains a filter
> propertry (haven't tried the filter property yet), but i think this is what
> i need.
> The class is placed in between the datasource and the viewer.
>
> /Peter
>
>
> "wdudek" <wdudek@newsgroup.nospam> wrote in message
> news:33440317-C16E-4019-8F37-B541E13B0C20@microsoft.com...
> > The later reply sounds like it would provide a means to do this, my
> > concern
> > however would be that you are then creating code that could be confusing
> > to
> > later developers. When they databind to the list and don't get all of the
> > records they may not realize at first that there is some sort of filtering
> > going on. By explicitly calling a method whose name implies the results
> > may
> > be filtered you do risk this issue.
> >
>
>
>

Peter Larsen [CPH]

10/30/2008 8:19:00 AM

0

Hi Bill,

I agree with you on this, messing with the enumerator without some kind of a
warning, is a no-go.

/Peter

"wdudek" <wdudek@newsgroup.nospam> wrote in message
news:04489324-4B49-419D-B8AA-4F57C1CBD001@microsoft.com...
> Yes I understand what you are trying to do, and using a class in between
> the
> data source and the viewer sounds like a good solution. My point was that
> embedding the filtering logic in the enumerator of a class could be
> confusing
> to someone 5 years down the road who has to work on the same code and
> isn't
> sure why they are not getting all of the results whent he enumerator is
> used.
>
> Bill
>