Hi!
I am trying to customize the layout of xamDataGrid programmatically by creating custom FieldLayouts with a colection of UnboundFields.
This approach works fine until i try to set the BindingPath property to an element of the System.Data.Objects.DataClasses.EntityCollection. This collection type does not support index-based iteration and provides the 'ElementAt' method to access specific elements.
I tried to set the binding as
1) UnboundField.BindingPath = new PropertyPath("[0].Value");
2) UnboundField.BindingPath = new PropertyPath("ElementAt(0).Value");
However none of this worked.
I alo tried a different approach - assigning values to cells in the InitializeRecord event. However this time the grid seemed to slow down and the cell value remained unchanged no matter what i did.
I would be most grateful if you could help me with the BindingPath issue.
Hello,
I do not think that this approach would give you the result you want. You can easily go around this problem by handling the FieldLayoutInitialized event. Here is one way to do this:
void xamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
{
List<string> fields = new List<string>();
foreach (Field field in e.FieldLayout.Fields)
if (field.IsExpandableResolved == false)
fields.Add(field.Name);
}
e.FieldLayout.Fields.Clear();
foreach (string s in fields)
UnboundField ub = new UnboundField();
ub.Name = s;
ub.Label = "Label of" + s + "Field";
ub.BindingPath = new PropertyPath(s);
e.FieldLayout.Fields.Add(ub);
(sender as XamDataGrid).FieldLayoutSettings.AutoGenerateFields = false;
Let me know if you have any questions on this.
Regards,
Alex.
Thank you for the quick response!
However i don't think that the suggested approach can help achieve what i wish. Perhaps i should be more specific about my scenario.
The problem is as follows: I have an object which needs to be presented in a hierarchical manner. The object has two properties:
1) PropertyA contains data that will be in the master level.
2) PropertyB contains data that will be in the detail level.
The catch here is that PropertyB has a PropertyC which is the EntityCollection (PropertyB is an EntityFramework Business Object ). There must be a single grid row for each PropertyB, which must have a single cell for each element of PropertyC. PropertyC can contain a varying number of elements which represent ProperyB features.
By default, xamDataGrid shows PropertyC elements as separate rows at the third hierarchy level. What i want to achieve is find a manner to convert these rows to the second hierarchy level cells.
That's why i was trying to set the BindingPath to a specific element index at the EntityCollection. That approach would have worked in case of List<T> for instance, but fails in my case.
Any suggestions?