CSLA .NET

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

Welcome to CSLA .NET Sign in | Join | Help
in Search

Get a list of fields from object 3.0.4

Last post 01-07-2009, 7:40 AM by esteban404. 2 replies.
Sort Posts: Previous Next
  •  01-05-2009, 4:19 PM 29484

    Get a list of fields from object 3.0.4

    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
  •  01-06-2009, 6:49 PM 29521 in reply to 29484

    Re: Get a list of fields from object 3.0.4

    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
  •  01-07-2009, 7:40 AM 29531 in reply to 29521

    Re: Get a list of fields from object 3.0.4

    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;
    }
View as RSS news feed in XML

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?
Powered by Community Server, by Telligent Systems