Choosing columns when binding to a collection using DataGridView

Posts   
 
    
hellbinder
User
Posts: 12
Joined: 30-Jan-2008
# Posted on: 12-Jan-2009 17:07:52   

Hi, I am trying to find out how (if possible) to show only the columns that I add in the DataGridView when binding to a collection.

The problem is that i have a collection which has many fields. I bind that to thr grid which I have only added two columns for test purposes. What I end up with is with the two columns I added being at the beggining with their respective data and then the REST of the collection fields. I just want to show the two columns.

Thanks in advance, Miguel Martorell

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Jan-2009 03:29:23   

Hi Miguel,

I'm not sure if you want to a) fetch only two fields or b) show only two fields. If are showing only two fields already but the routine fetch ALL fields, then you could use excluding/including fields feature.

Now, if you just want to limit the columns you see at grid, you should add just two DataBound columns at DataGridView, or just TemplateFields/ItemTemplate.

David Elizondo | LLBLGen Support Team
hellbinder
User
Posts: 12
Joined: 30-Jan-2008
# Posted on: 13-Jan-2009 15:41:55   

I just want the datagriview to show 2 columns. Let's say for examply I have a User Collection.

For this example I do.

UserCollection uc= new UserCollection(); uc.GetMulti(null) someGridView.DataSource = uc; From that I want to be able to limit the grid view to two columns only. I am able to add two columns in design time to the grid but when I run it, the first two columns that I designed appear perfectly, but the REST of the columns from the collection also appear.

You mentioned excluding/including fields feature and I'm not sure how to use it. For the collection itself I only see the "FetchExcludedFields method". Is that what I have to use? confused

Any simple example would help.

Thank you,

Miguel Martorell

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Jan-2009 22:09:45   

Excluding/Including fields is not really what you need here - it is really designed to prevent having to pull down large BLOB fields from the DB if they are not really needed - the properties will still be present on the entity but will be null.

It looks like setting the .DataSource property of the grid is causing it to reload all of the data columns. Have you tried hiding the unwanted columns in code?

BTW - if you want a decent grid control the Janus GridEx is very good, and works nicely with LLBLGen entities and collections.

Matt

hellbinder
User
Posts: 12
Joined: 30-Jan-2008
# Posted on: 13-Jan-2009 22:55:26   

I have a method that hides unwanted columns. I was just wondering if there was a way without having to use code. It's just that it surprises me that when using a collection as DataSource it will bring out ALL the columns ignoring the design I chose. (Add wanted columns and those are the first to appear, still the rest of the data columns appear after).

Well, I guess I'll have to go with code on this. Unless somone still has a better solution.

ThAnKs FoR tHe HeLp!!smile

Miguel Martorell

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jan-2009 02:48:54   

Hi Miguel,

Exclude/Include fields are useful for performance in the fetch process, but the entity still has all the fields. What you are talking about is different, and it is in the context of GUI controls, so I think your method (hide columns) or other methods (TemplateFields or selective fields in gridView) should be used.

David Elizondo | LLBLGen Support Team