This example demonstrates how to display and edit properties of complex objects (Dictionary values, DynamicObject descendants) in DXGrid. The GridBindingHelper helper class is used to bind grid columns to complex properties of this kind. Here are instructions on how to use it:
1) Use the GridBindingHelper.ItemsSource attached property to assign a datasource instead of the built-in DataSource property;
2) Use the GridBindingHelper.ComplexFieldName attached property to specify the field name;
3) Set the column's UnboundType property value.
We also do have plans to introduce built-in support for this functionality. Please track this suggestion to stay informed on our progress over this item:
S136096: Binding - Support binding to complex object properties
Question Comments
Added By: (no info) at: 7/23/2012 10:26:29 AM
Thanks for the example, it works great, except that it has one minor bug - in GridColumnBindingHelper.cs ComplexPath constructor has this lines of code:
if(!string.IsNullOrEmpty(index) && Char.IsDigit(index[0])) {
pathPart = new PathPartList(path, int.Parse(index));
which will throw exeception if index variable contains something like this "322_PMI" as first character is digit, but whole string cannot be (obviously) parsed to int.
In order to make it work for our needs (as I've had complex paths like this "Items[322_PMI].Quantity") I've changed code to this (not fully tested though):
public ComplextPath(string complexPath)
{
string[] paths = complexPath.Split('.');
for (int i = 0; i < paths.Length; i++)
{
string path = paths[i];
int braceIndex = path.IndexOf("[");
string index = null;
if (braceIndex >= 0)
{
index = path.Substring(braceIndex + 1, path.Length - braceIndex - 2);
path = path.Substring(0, braceIndex);
}
if (string.IsNullOrEmpty(index))
{
pathParts.Add(new PathPartSimple(path));
}
else
{
int parsedIndexAsInt32;
bool indexIsInt = int.TryParse(index, out parsedIndexAsInt32);
if (indexIsInt)
{
pathParts.Add(new PathPartList(path, parsedIndexAsInt32));
}
else
{
pathParts.Add(new PathPartDictionary(path, index));
}
}
}
}
Does this work with ICollectionView?
If I create ICollectionView using CollectionViewSource.GetDefaultView(Rows) and bind it, it doesn't get the updates.
ICollectionView provides lot of options for sorting & filtering. Working with ICollectionView will be really good.