I have been having problems getting the Infragistics WinGrid display the information in deep hierarchical relationships for the last couple of days.
After some research, and some previous issues i've had to deal with, I think I nailed it down to the implementation of ITypedList.GetItemProperties() in the ListBase<T> class.
The current implementation looks in the first element of the listAccessors[] array, and this has worked fine as long as there aren't more than 1 nested collections. However when the nesting of the collections goes beyond 1 level, the last element in the listAccessors parameter is the one most relevant, according to this article found at http://weblogs.asp.net/fbouma/articles/115837.aspx
We have to solve the mistery of the listAccessors array before we can
move on. What does it contain? As said, it contains all properties the
user has used to navigate to the property which exposes the collection
of objects we have to provide the property descriptors for. So this
means that we can ignore the complete array except the last entry! The
last entry in the array will be the property descriptor we're looking
for. This is essential information as it will make our code much
simpler.
I changed my implementation as follows, and it works like a charm for me.
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
if (listAccessors == null || listAccessors.Length == 0)
{
return _propertyCollection;
}
else // Expect only one argument representing a child collection
{
if (_childCollectionProperties == null)
_childCollectionProperties = new Dictionary<string, PropertyDescriptorCollection>();
Type relevantType = listAccessors[listAccessors.Length - 1].PropertyType;
string typeName = relevantType.FullName;
if (_childCollectionProperties.ContainsKey(typeName))
{
return _childCollectionProperties[typeName];
}
else
{
PropertyDescriptorCollection props = EntityHelper.GetBindableProperties(relevantType);
_childCollectionProperties.Add(typeName, props);
return props;
}
}
}
I know this has frustrated other people as well, if this looks kosher to you guys, can you include it in the templates?
I don't know much about complex databinding, so if this is wrong, please let me know, I don't want to suffer in agony later on because of this.
"Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein