CodeSmith Community
Your Code. Your Way. Faster!

DataBinding to a hierarchy of sub collections deeper than 2+ levels

Latest post 02-22-2007 1:10 PM by bgjohnso. 5 replies.
  • 02-13-2007 12:06 PM

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    DataBinding to a hierarchy of sub collections deeper than 2+ levels

    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
    • Post Points: 35
  • 02-13-2007 1:07 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    Re: DataBinding to a hierarchy of sub collections deeper than 2+ levels

    Graw,

    Thanks for the contribution.  I was actually playing around with this a few days, but hadn't actually got around to getting to a fix.  I've implemented your fix and just tested it using an Infragistics WinGrid and I was able to drill down 3 levels (Customers --> Orders --> OrderDetails) with no issues.

    This has been commited as SVN 486.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 02-21-2007 5:31 PM In reply to

    • sdavison
    • Top 150 Contributor
    • Joined on 01-25-2006
    • Posts 26
    • Points 805

    Re: DataBinding to a hierarchy of sub collections deeper than 2+ levels

    We're in the process of evaluating several third-party controls and I'm having a nut of a time getting the Infragistics WinGrid to work as I expected.  Are you using the typed datasources or the ObjectDataSource?  Are you using declarative code or setting the properties in your code-behind?  It would be really helpful for me (and likely many more people!) if you could post your .aspx and .cs code that makes the WinGrid display the Customer/Orders/OrderDetails heirarchy from NetTiers objects.  Many thanks!
    • Post Points: 35
  • 02-21-2007 7:20 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    Re: DataBinding to a hierarchy of sub collections deeper than 2+ levels

    Hmmm...  Well, the WinGrid is for WinForms and not ASP.Net.  I haven't actually tried doing anything with the Infragistics UltraWebGrid.  I would hope that you could use the strongly typed datasource...  Can you get the grid to display multiple levels of details using a DataSet?  I'll try and take a look at this tomorrow. 

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 02-21-2007 11:35 PM In reply to

    • sdavison
    • Top 150 Contributor
    • Joined on 01-25-2006
    • Posts 26
    • Points 805

    Re: DataBinding to a hierarchy of sub collections deeper than 2+ levels

    You can definitely get the UltraWebGrid to display multiple bands for a dataset that has relations built into it (you can see it in action here).

    Seems like other people on this forum have made it work using an ObjectDataSource but I can't seem to make it work correctly so any pointers would be most appreciated! 

    • Post Points: 35
  • 02-22-2007 1:10 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    Re: DataBinding to a hierarchy of sub collections deeper than 2+ levels

    Ok, here's a sample using the UltraWebGrid (this is version 5.3; old I know but it should work with the later versions as well).  This is using the Northwind database, specifically the Orders and OrderDetails tables.  I am using a strongly typed datasource and deep loading the OrderDetails collection.  Also, the key to getting the sub-collections to display is to set DisplayLayout.ViewType equal to Heirarchical or OutlookGroupBy.  I have also limited the datasource to just return a few orders.  I stripped out all of the infragistics formatting code so that you can easily see what is required to make this all work.

    <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" DataSourceID="OrdersDS" >
           <DisplayLayout ViewType="OutlookGroupBy" >
           </DisplayLayout>
        </igtbl:UltraWebGrid>
    
        <data:OrdersDataSource runat="server" EnableCaching="false" EnablePaging="true" ID="OrdersDS"  
         EnableSorting="true"
         SelectMethod="GetPaged" EnableDeepLoad="true" >
          <DeepLoadProperties>
             <Types>
                <data:OrdersProperty Name="OrderDetailsCollection" />
             </Types>
          </DeepLoadProperties>
         <Parameters>
          <data:CustomParameter Name="WhereClause" DefaultValue="OrderID between 10248 and 10260" />
         </Parameters>
         </data:OrdersDataSource>
    

    Hope this helps.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems