CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Get a list of fields from object 3.0.4

rated by 0 users
This post has 2 Replies | 2 Followers

Top 50 Contributor
Posts 122
esteban404 Posted: Mon, Jan 5 2009 4:19 PM
I'm writing a WinForms project. I have a user control with a grid (DevExpress XtraGrid) in the UI whose column visibility need to change to accommodate the business object content, rules and job requirements. To hide the columns, I need to get the public field names from the object and hide them. I haven't found what I'm looking for yet. Do I add a list to contain the names I need or is there an existing way to get it from the object itself? I think there is in later versions, but I'm not able to use the latest version.

I'm thinking of something like this where the column Caption is the same as the field name using an object data source:
for (int x = 0; x {
if (myList.Contains(this.gridView1.Columns[x].Caption))
this.gridView1.Columns[x].Visible = true;
else
this.gridView1.Columns[x].Visible = false;
}

On second thought, I may need an object for each job type so that live editing can be done on the form, binding each grid to this generic data source object.

Doing that, seems to cause a chicken/egg problem: one object data source for form design and the data source for that design source would change making some design fields inaccessible possibly causing the app to complain violently. There are currently 14 distinct business cases and distinctive UI needs for the data. I have all the shared fields in a base class and that's working fine. Now the UI needs to be reconciled.

Thanks in advance for any suggestions,

_E
Top 10 Contributor
Posts 7,309

You can use reflection to get a list of properties or fields in an object. CSLA does this in UndoableBase in 3.0, and that might give you some ideas.

Rocky

Top 50 Contributor
Posts 122
That's perfect, just renamed my column names to the field names and bingo! I knew I'd seen something.

Thanks!

foreach (FieldInfo field in fields)
{
if (this.gridView1.Columns.Contains(this.gridView1.Columns.ColumnByName(field.Name)))
this.gridView1.Columns.ColumnByName(field.Name).Visible = true;
}
Page 1 of 1 (3 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems