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

GridView Hierarchy

1 Answer 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Praveen Kumar
Top achievements
Rank 1
Praveen Kumar asked on 20 May 2009, 10:50 AM
I am using Hierarchy grid view
what i need is how can expand or collapse all childtemplates in the Hierarchy grid view 
And also suggest me how to know all the features of Hierarchy grid view (can i display total number of records on top of each childtemplate...)

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 20 May 2009, 01:00 PM
Hello Praveen Kumar ,

You can expand all child views by iterating over all parent rows and setting the IsExpanded property to true. You should call the BeginUpdate and EndUpdate methods to avoid unnecessary updates. Please take a look at the code snippet below:

radGridView1.GridElement.BeginUpdate(); 
foreach (GridViewDataRowInfo row in radGridView1.Rows) 
    row.IsExpanded = true
radGridView1.GridElement.EndUpdate(); 

You should use a custom cell to show the number of records available in the child view. To do this, create a new cell element that inherits from GridDataCellElement and handle its SetContentCore method. You should also handle CreateCell event and to add an unbound textbox column to your grid. Here is the code:

this.radGridView1.CreateCell += new GridViewCreateCellEventHandler(radGridView1_CreateCell); 
this.radGridView1.Columns.Add(new GridViewTextBoxColumn("ChildRows""")); 
this.radGridView1.Columns["ChildRows"].ReadOnly = true
 
void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e) 
    if (e.Row is GridDataRowElement && e.Column.HeaderText == "ChildRows"
    { 
        e.CellElement = new MyDataCell(e.Column, e.Row); 
    } 
 
public class MyDataCell : GridDataCellElement 
    public MyDataCell(GridViewColumn column, GridRowElement row) 
        : base(column, row) 
    { 
    } 
 
    protected override void SetContentCore(object value) 
    { 
        GridViewDataRowInfo rowInfo = (GridViewDataRowInfo)this.RowInfo; 
        GridViewRowInfo[] rows = rowInfo.ViewTemplate.ChildGridViewTemplates[0].GetChildRows(rowInfo); 
        if (rows != null && rows.Length > 0) 
        { 
            this.Text = rows.Length.ToString(); 
            return
        } 
        this.Text = ""
    } 

To get the number of all rows inside the child template, just check the Count property of its Rows collection:

int totalChildRowsCount = this.radGridView1.MasterGridViewTemplate.ChildGridViewTemplates[0].Rows.Count; 
 

I hope this helps. If you have more questions, I will be glad to answer.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Praveen Kumar
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or