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
UltraWinGrid and BindingSource with Complex Property
posted

Hi,

I'm validating the Infragistics UltraGrid (version 6.3) for use in a project. Is there a way to use a bindingsource with complex properties? Example:

class cAddress
{
     public string Street { get; set; }
}

class cResident
{
     public string Lastname { get; set; }
     public cAddress Address { get; set; }
}

I tried to do the following:
ArrayList _Residents = GetResidents() //returns cResident Collection
BindingSource _BindingSource = new BindingSource(_Residents);
UltraGrid _UltraGrid = new UltraGrid(); // Would be initialized in designtime for columns etc.

_UltraGrid.DisplayLayout.Bands[0].Columns[1].Key = "Lastname";
_UltraGrid.DisplayLayout.Bands[0].Columns[2].Key = "Address.Street";

The property for column 2 does not show up.

Any suggestions or help would be great.

Thanks,
Iwe

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Iwe,

    You can't set the Key on a bound column. When you assign the DataSource of the grid, the grid will automatically build the bands and columns based on the data source. In this case, you would get a grid with two columns: LastName and Address. The Address column would not be editable, since it's an object the grid does not know how to edit.

    There are a number of ways you can get this to work. The most elegant way (and also the most complicated) would be to implement ITypedList on your cResident class. You could create property descriptors that are aware of the cAddress class and it's properties and return the properties of the Address instance. Basically, what you do is handle GetPropertyDescriptors on ITypedList and remove the property descriptor for Address and replace it with descriptors for Street and any other sub-properties of Address that you want displayed at the root level. As I said, this can be pretty daunting, especially if you are not familiar with ITypedList and PropertyDescriptors. But it's an elegant solution because it will work with any control, not just the grid. The good news is that I wrote a sample of this a while ago and I am attaching it here.

    If you want to do this an easier way, then what I would do is use the InitializeLayout event of the grid to hide the Address column. Then add an unbound column to the grid for Street and any other Address properties you want. You would then use the InitializeRow event to populate the Street column with the Address.Street. If the data is editable, you would use BeforeRowUpdate to take the Street value from the grid and update the Address.

    WinGrid_UsingITypedListToFlattenTheData_CS.zip
Reply Children