I have a dynamic datasource which is bound to a ultracombo control. Datasource can be of type DataTable or List<T>. T Represents a certain class where each class has multiple column attributes that describe the look of a column (ColumnAttribute (int Index, string Title, string BoundColumnName, int Width).
I think I have to create a band, create some columns etc. and then add the band to DisplayLaout.BandsSerializer. Is this correct? I only want to do this once. But when I look at Bands.Count there is allways 1. Means there is allready a band. This is the one created during databinding?
Is ther a best practice to achieve this?
Kind Regards
Patrick
Patrick,
You should never be using the BandsSerializer object as this is meant to be used only by the Infragistics framework. The structure of the columns is determined by the information that is returned by the .NET BindingManager, in terms of what it can deduce about the structure of the object. When you bind your combo to the data source, the columns that are made available are the public properties that the BindingManager can locate (or returned by the ITypedList interface, if implemented). You can certainly create your structure at design-time without binding the control, but you need to ensure that the keys of the columns (and the band itself) align with the names of the properties (and table/DataMember).
If you want to do specific formatting at run-time, you can handle the InitializeLayout event of the combo, which is fired after you bind the control and is considered the best-practice location of performing initialization logic. This has the added benefit that if you re-bind the control later, your initialization logic will be re-evaluated.
-Matt
Matt,
thank you for this information. I used the InitializeLayout event and implemented the following code.
object[] attrs = this.boundParameter.GetType().GetCustomAttributes(typeof(ColumnAttribute), false);
if (attrs.Length == 0) return;
Infragistics.Win.UltraWinGrid.UltraGridBand band = e.Layout.Bands[0];
foreach (object attr in attrs){ ColumnAttribute c = attr as ColumnAttribute; if (band.Columns.Exists(c.BoundColumn)) { Infragistics.Win.UltraWinGrid.UltraGridColumn column = band.Columns[c.BoundColumn]; column.Width = c.Width; column.Header.Caption = c.Title; column.Header.VisiblePosition = c.Index; column.Hidden = !c.Visible; }}
This worked fine for me.
Regards
Just as an aside, if you want to deal with property descriptors and using that approach to deal with the order of columns and what's visible, you might consider implementing ITypedList on your data source instead of doing it this way. Or maybe it's just something to keep in mind for next time :-)