Handle different collections in one grid

Posts   
 
    
mag
User
Posts: 13
Joined: 28-Oct-2009
# Posted on: 28-Oct-2009 17:45:32   

Hey there,

I'd like to do the following thing:

In many parts in our application we use a separate windows where the user can select a record from a list (we are using datagridviews). These grids are binded with collections (eg in one window with customerCollection, in another with orderCollection). How can I manage that to avoid creating several windows for each list?

When the user selected a record and closed the windows it should be able to get the selected entity...

I hope it's understandable and I get some help or useful ideas... thx

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Oct-2009 17:56:18   

You can try to use a generic collection and set the type at runtime. Also you can try to return IEntity, or EntityBase types.

And the caller should cast it to the typehe is quering.

mag
User
Posts: 13
Joined: 28-Oct-2009
# Posted on: 29-Oct-2009 08:40:11   

Good morning, thank you for your post

I tried to solve it this way:

The caller pass the entityType to the called window where I create IEntityCollection object:

IEntityCollection entityCollection = GeneralEntityCollectionFactory.Create(entityType);

Now I can bind this collection to my datagridview. This works fine, all records will be shown correctly.

But now my problem is that I don't know how to get the selected record when closing the form. Normally I get current record by calling elementAt function of collection using index of currentRow from datagridview. The IEntityCollection instance doesn't offer this function. How can I handle that? Or do I have to strike another way?

some additional infos: I'm using self-servicing mehtode LLBLGen Pro version: 2.6 Final

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Oct-2009 08:51:43   

IEntityCollection is an IEnumerable, so I guess you can just use the indexer [], as in collection[index].

mag
User
Posts: 13
Joined: 28-Oct-2009
# Posted on: 29-Oct-2009 08:57:00   

Shame, I really thought I tried that... flushed

Works fine, thank you for your help.