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.
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.
In entity Framework you want to bing to the reference of the parent using the Value
For example
="BvoteProvidersReference.Value.EzeCode">
Arrhhh, sorry - just re-read your initial post - I sort of missed the point and made an incorrect assumption (I've not used EntityCollection before).
Your work around sounds quite good to me, although I can appreciate now that it would be better if you could use the ElementAt method within the PropertyPath.
I'd have probably tried inheriting from EntityCollection and adding an indexer (if that's even possible)... but without modifying the framework generated objects, I'm afraid I've reached the limits of my knowledge (which happens too easily) :-)
I'd too be interested to know if there is a better way.
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 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!
Regards,