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

Multiple Child Templates

3 Answers 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 24 Aug 2011, 11:40 PM
Hi there,

I'm currently evaluating the Telerik RadControls for WinForms and I'm trying to accomplish something with the DataGrid component. I am wondering if there is any way to specify different child templates for the top level rows in the grid.

I have a dataset that consists of a List<ICommonData>. I have 2 classes (say ClassA and ClassB) that implement ICommonData. My datasource contains a list of both ClassA and ClassB objects. The parent rows of the grid show all the properties declared in ICommonData. What I want is when the user expands the parent row, I want them to see a sub grid that shows other ClassA or ClassB columns depending on what data object that row was bound to. Basically I need the ability to specify dynamically which template each row uses when displaying the child grid.

Is there any way to do this?

Thanks,
Josh

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 29 Aug 2011, 12:28 PM
Hello Josh, I answered to your question in your support ticket regarding the same issue. Please avoid posting the same question twice, as this may slow down our response. Thank you for your understanding.

Should you have any other questions, do not hesitate to ask.
 
Regards,
Jack
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Miloš Sommer
Top achievements
Rank 1
answered on 01 Sep 2011, 01:13 PM
Hello,

could you send me an answer for Josh too, please?

 

I think it can solve my problem i have written here:

http://www.telerik.com/community/forums/winforms/gridview/hiearchical-grid.aspx


Thank you Misa.
0
Jack
Telerik team
answered on 02 Sep 2011, 02:15 PM
Hi Michaela,

As requested, I am posting here my response to the question from Josh:

"Hi Josh,

Thank you for contacting us.

Yes, this is possible. Please take a look at the GridView - Hierarchy - Tabbed Views example in our demo application. It implements a highly similar scenario - a parent view that relates to many child views. The child views are presented in different tabs. You can find more information in this topic in our online documentation.

All you need to do is hide the desired tab programmatically. This can be done when handling theViewCellFormatting event. Please consider the code snippet below:"

Copy Code
this.radGridView1.ViewCellFormatting += newCellFormattingEventHandler(radGridView1_ViewCellFormatting);
 
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridDetailViewCellElement cell = e.CellElement as GridDetailViewCellElement;
    if (cell != null)
    {
        GridViewDetailsRowInfo detailsRow = (GridViewDetailsRowInfo)cell.RowInfo;
        GridViewHierarchyRowInfo hierarchyRow = (GridViewHierarchyRowInfo)detailsRow.Owner;
        if (hierarchyRow.Index % 2 == 0)
        {
            cell.PageViewElement.Items[0].Visibility = ElementVisibility.Visible;
        }
        else
        {
            cell.PageViewElement.SelectedItem = cell.PageViewElement.Items[1];
            cell.PageViewElement.Items[0].Visibility = ElementVisibility.Collapsed;
        }
    }
}

I hope this helps. We will answer your question in your forum post.

Should you have any other questions, do not hesitate to ask.
 
All the best,
Jack
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Josh
Top achievements
Rank 1
Answers by
Jack
Telerik team
Miloš Sommer
Top achievements
Rank 1
Share this question
or