Give these two classes (forgive me for any bad syntax) for the sake of the issue:
public class Pencil{ public int Length { get; set; } public bool IsMechanical { get; set; }}
public class PencilCase{ private BindingList<Pencil> _pencils = new BindingList<Pencil>(); public int Color { get;set; } public BindingList<Pencil> Pencils {get; set; }}
Imagine binding a 'BindingList<PencilCase>' to a grid and that BindingList is empty (meaning zero items in it and not null). I can see that I have a single column in the first band (that column being Color) and another band called Pencils. In that second band I cannot see the columns that make up Pencil's properties. Shouldn't I be able to see 'Length' and 'IsMechanical' in that second band?
My problem is that I'm trying to format the way the columns look once after the list had been bound to the grid. I can format the looks of the band 0 but I can't seem to forumat the columns for band 1 because those columns don't seem to be there.
Thanks for any help :)
Gally
Gally,
I think that this has to do with the fact that since there are no rows, and especially that there is no child row in the first parent row, the .NET BindingManager is unable to determine the structure of the data, so the grid cannot properly get the columns. The two workarounds that I can think of are to either add rows to your data, or implement ITypedList on the Pencil class.
-Matt
Hey Matt,
Thanks for replying.
Thats what I don't get. If there is no rows, it will still create the parent row columns just not the child row columns. My guess is that Infragistics is using reflection to do this. It just seems that there isn't that extra step to dive deeper and use reflection on the child.
I think that should be the case here since the main band is getting its structure directly. I just tried this out and verified that the second band has the two columns; try this class instead of BindingList<Pencil> for the child band:
public class PencilList : BindingList<Pencil>, ITypedList{ private PropertyDescriptorCollection properties; public PencilList() : base() { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties( typeof(Pencil), null); properties = pdc; } #region ITypedList Members public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[ listAccessors) { PropertyDescriptorCollection pdc = null; if (listAccessors == null) pdc = this.properties; else pdc = ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType); return pdc; } public string GetListName(PropertyDescriptor[ listAccessors) { return typeof(Pencil).Name; } #endregion}
Hi Amiram-
Unforutantely that doesn't play so nice when your're working with a CAB architecture.
Matt-
If I implement ITypedList that should be all I would need to do, and Infragistics takes it from there when I attempt to bind an empty list?
The grid does not use reflection to get this information, it uses the .NET BindingManager, which then provides the property descriptor for each column (including one that represents the child band). If the binding manager doesn't have a row in this child area, it is unable to determine the structure; this is not specific to the grid. The ITypedList workaround allows the grid to determine the structure when the BindingManager is unable to do so.
Another idea, you can set the data source at design time.
Go to DataSource in the grid properties window and open the drop down.
Select "Add Project Data Source..."
In the wizard select "Object" and then find you parent object type and click "Next".
After the wizard finished you'll see all the columns and a BindingSource.
In runtime just put your data in the BindingSource.DataSource.