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?
Hi Qwertyoid,
I also had fun trying to get the BindingPath on an UnboundField set to the correct path. I *think* I've followed your description and *think* your situation is similar to ours.
Have you tried something like the following?
UnboundField.BindingPath = new PropertyPath("PropertyC[0].Value");
As you're creating the UnboundFields for the second level of the hierarchy, but you want to use the collection based PropertyC items as the values for the cells at that level?.... you need to include PropertyC's name before the square bracket (if I've understood correctly).
I'm assuming your PropertyC EntityCollection can be accessed by index? (we've set ours to be indexed by a guid). Also, do the items in this collection have a Value property of type string?
Our "PropertyC" is called "Values", which is a collection of IValue objects, accessed by a string that contains a guid. The IValue has a string property called StoreValue, to access its underlying content. So, the syntax we use is:
.BindingPath = New PropertyPath("Values[" & cell.QueryPropertyID & "].StoreValue")
I think you have the right approach, just need to get the path sorted out... hope this is of some help!
Dave
Hi Pentana,
Thank you for your response. Yes, your understanding of the described scenario is right. The problem is that System.Data.Objects.DataClasses.EntityCollection<T> (the PropertyC type) is not indexable. I'd like to avoid any modifications of the Entity Framework-generated business objects as they satisfy my needs in every other way.
I've came up with a workaround, introducing a PropertyD into my object, which is an array holding a set of PropertyC elements an is indexable. Doesn't seem to be the best approach, but it does work.
I'd still be glad to hear if there are any more traditional ways to set the binding in the described scenario.
Hi
I've also this kind of problem which i get an EntityCollection<T>. Currently i'm able to access an item from the collection using ivalueconverter approach, however i'm not sure how to access a property of that item. Eg.
my collection: EntityCollection<Orders> orders
field.BindingPath = new PropertyPath("Orders");field.Converter = converter;field.ConverterParameter = converterParameter;
* The converter will return an item of type order.