Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
WinGrid Binding to Object Hierarchy
posted

I have an object structure with a multilevel hierarchy.

I have a collection of Station Objects which each have a single Unit object, and a Config Object.

I want to display the collection of Station objects in the wingrid, showing only the Station.Name, the Station.Unit.Name, and the Station.Config.Name as columns in a single Band.

I have bound the Grid to the collection of Station Objects at runtime, and the toplevel properties are correctly showing as columns (ie the Station.Name, the Station.ID etc), but the second level object properties are not showing correctly (ie the Station.Unit.Name, the Station.Config.Description etc). They are showing as columns, but the value in the columns is "Station.Unit" and "Station.Config" etc

Is there a way of displaying the values correctly?

Thanks

Paul

Parents
No Data
Reply
  • 735
    posted

    Create properties in your Station object that return the values from child objects.

     [DescriptionAttribute(@""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
     [DataObjectField(false, false, false)]
     public string UnitName
     {
          get { return base.Unit.Name; }
      }

    Oh, I forogot to mention that these properties would then be available as bindable columns in your Station object. Don't forget to reset the data source so that the new columns show up.

Children
No Data