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

Hierarchical RadGrid with Auto-Generated Columns: Converting Column Type

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ET
Top achievements
Rank 1
ET asked on 05 Nov 2010, 11:49 PM
Hey Telerik pros,

Could use your help on this one...

I'm trying to use a nested RadGrid to show a BOM (bill of materials) i.e. parts are composed of simpler parts, which may in turn be composed of even simpler parts, etc.

I have a grid like so, using HierarchyLodeMode="ServerBind", and Unique_Id and Parent_Id to create a self-referencing hierarchy.

<telerik:RadGrid ID="RadGrid1" runat="server"OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender"AllowSorting="True">
    <MasterTableView HierarchyLoadMode="ServerBind" AllowSorting="true" DataKeyNames="Unique_Id, Parent_Id">
        <SelfHierarchySettings ParentKeyName="Parent_Id" KeyName="Unique_Id" />
    </MasterTableView>
    <ClientSettings AllowExpandCollapse="true">
        <Selecting AllowRowSelect="True"></Selecting>
    </ClientSettings>
</telerik:RadGrid>

Then, in the code-behind, using OnNeedDataSource event:

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = GetDataTable(); //fetches data, returns DataTable
}

And in the PreRender, hiding the expand column for those rows that don't have anything nested beneath them:

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    HideOrShowExpandColumnRecursive(RadGrid1.MasterTableView);
}
 
protected void HideOrShowExpandColumnRecursive(GridTableView tableView)
{
    GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
        foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
        {
            if (nestedView.Items.Count == 0)
            {
                TableCell cell = nestedView.ParentItem["ExpandColumn"];
                cell.Controls[0].Visible = false;
                nestedViewItem.Visible = false;
            }
            if (nestedView.HasDetailTables)
            {
                HideOrShowExpandColumnRecursive(nestedView);
            }
        }
    }
}

And all that works great, I can get the self-referencing hierarchical grid of X levels (where X isn't known until you get the data).

Now, my problem is trying to convert the type of these auto-generated columns, from the regular GridBoundColumn to something like GridHyperLinkColumn. I can't figure out how to do that, maybe it's not possible?

As another approach, I tried adding a GridHyperLinkColumn to the nested views during the PreRender event, but I can't get that to work either.

Does anybody have any suggestions on how to either a) convert the type of these auto-generated columns or b) dynamically add another column to the grid? All I really want is to be able to add a hyperlink to each row in this type of nested grid.

Much thanks,
ET

1 Answer, 1 is accepted

Sort by
0
ET
Top achievements
Rank 1
answered on 09 Nov 2010, 09:35 PM
Ok, I'm posting an "answer" to my own question in case anybody else views this post and is looking for similar help:

After opening a support ticket, Telerik suggested a better way to do this: the new (2010 Q3) TreeList control.

That's exactly what I was looking for, and seems like a preferable approach to using the nested Grid.

-ET
Tags
Grid
Asked by
ET
Top achievements
Rank 1
Answers by
ET
Top achievements
Rank 1
Share this question
or