This is a migrated thread and some comments may be shown as answers.

Selecting Children for Heirarchical view from a Generic Collection

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Mark asked on 15 Jun 2011, 01:58 PM
Hi,

I'm sure you have addressed this somewhere before, but I could not find it.

I am assigning a generic collection as the DataSource of a RadGrid control. The Items in the collection have one member which is also a generic collection which provide the children.

For Example:

public class WorkOrderDetails
{
    protected readonly IWorkOrder _workOrder;
    protected readonly List<ResourceRequirement> _resources = new List<ResourceRequirement>();
    public WorkOrderDetails(IWorkOrder wo)
    {
        _workOrder = wo;
        foreach (IWoResources res in wo.ResourcesChildren)
        {
            _resources.Add(new ResourceRequirement(res));
        }
    }
    public string WoNumber { get { return _workOrder.WoNumber; } }
    public string Title
    {
        get { return _workOrder.Description; }
    }
    public List<ResourceRequirement> Resources
    {
        get { return _resources; }
    }
}
public class ResourceRequirement
{
    private IResources _data;
    public ResourceRequirement(IResources res)
    {
        _data = res;
    }

      //
      // Summary
      //    The Unique ID of this ResourceRequiment (which is a "Skill").
      public string ID { get { return _data.ResourceId; } } 

    //
    // Summary:
    //     The property for the planned_hours column of the TabWare database wo_resources
    //     table.
    public decimal PlannedHours { get { return _data.PlannedHours; } }
    //
    // Summary:
    //     The property for the remaining_hours column of the TabWare database wo_resources
    //     table.
    public decimal RemainingHours { get { return _data.RemainingHours; } }
    //
    // Summary:
    //     The property for the workers column of the TabWare database wo_resources
    //     table.
    public int Workers { get { return _data.Workers; } }
}

The assignment looks something like this:

List<WorkOrderDetails> list = factory.GetWorkOrders();
RadGrid1.DataSource = list;

My goal is to display the Work Orders with the ResourceRequirement children grouped under each WorkOrderDetail line.
For Example:

WoNumber    Title
000010202    Repair light fixture
      ID             Planned Hrs           Remaining Hrs            Workers
      Electician      8.0                         8.0                            1
      Welder          8.0                         8.0                            1

I figured out how to get the headers defined, but I currently have no content showing up for the child rows. Here is my markup:

<telerik:RadGrid
    ID="rgPlannedWorkOrders" runat="server" 
    Width="480px" Height="392px"
    AutoGenerateColumns="False" AllowSorting="True"
    Skin="Sunset" GridLines="Vertical" CellSpacing="0" 
    AutoGenerateHierarchy="true">
    <ClientSettings>
        <Selecting AllowRowSelect="True" />
    </ClientSettings>
    <MasterTableView Width="100%"
        HierarchyDefaultExpanded="True" HierarchyLoadMode="ServerBind">
        <Columns>
            <telerik:GridBoundColumn DataField="WoNumber" 
                FilterControlAltText="Filter WoNumber column" HeaderText="WoNumber" 
                ReadOnly="True" SortExpression="WoNumber" UniqueName="WoNumber">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Title" 
                FilterControlAltText="Filter Title column" HeaderText="Title" ReadOnly="True" 
                SortExpression="Title" UniqueName="Title">
            </telerik:GridBoundColumn>
        </Columns>
        <DetailTables>
            <telerik:GridTableView Name="SubLevel1" ShowHeadersWhenNoRecords="false"   AutoGenerateColumns="false">
                <%-- This level holds items of Type2 --%>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" 
                        FilterControlAltText="Filter ID column" HeaderText="ID" 
                        ReadOnly="True" SortExpression="ResourceId" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="PlannedHours" DataType="System.Decimal"
                        FilterControlAltText="Filter PlannedHours column" HeaderText="Planned Hrs" ReadOnly="True" 
                        SortExpression="PlannedHours" UniqueName="PlannedHours">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="RemainingHours" DataType="System.Decimal"
                        FilterControlAltText="Filter RemainingHours column" HeaderText="Remaining Hrs" 
                        ReadOnly="True" SortExpression="RemainingHours" UniqueName="RemainingHours">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Workers" DataType="System.Int32" 
                        FilterControlAltText="Filter Workers column" 
                        HeaderText="# Workers" ReadOnly="True" SortExpression="Workers" 
                        UniqueName="Workers">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
            </DetailTables>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
        </EditFormSettings>
        <GroupHeaderItemStyle Height="32px" />
        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
    </MasterTableView>
    <GroupingSettings GroupContinuesFormatString="" GroupContinuedFormatString=""></GroupingSettings>
    <FilterMenu EnableImageSprites="False"></FilterMenu>
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Sunset"></HeaderContextMenu>
</telerik:RadGrid>


So, my question is: how do I tell the control to use the "Resources" property of the WorkOrderDetails item to fill the content of the second level of the heirarchy?

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 20 Jun 2011, 08:57 AM
Hi Mark,

 First you should specify the relationship between the master and the detail tables as in normal hierarchy  - Hierarchical declarative relations (using the ParentTableRelationship property of the grid). Then in order to address the subobject of the inner collection you can use a standard dot(.) syntax as shown in this help topic and live demo.

Best wishes,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Mark
Top achievements
Rank 2
Answers by
Marin
Telerik team
Share this question
or