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

Could not set the child grid height

4 Answers 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hari
Top achievements
Rank 1
Hari asked on 11 Jun 2009, 10:59 AM
Hi,

I am developing a windows application using radGrid (Hierarchical grid). I want to see only 5 child records at a time when parent row is expanded. Currently I have 50 child records and All the child records are getting displayed. I want to restrict the number of child records to be viewed, So that the remaining records can be scrolled.

Please suggest me if we can achieve this.


Thanks
Hari Kumar

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 11 Jun 2009, 11:44 AM
Hi Hari,

You can restrict the child view height by setting the MaxHeight property when handling the ChildViewExpanded property. Please take a look at the sample below:

void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e) 
    e.ChildRow.MaxHeight = 300; 

I hope this helps. Please write me back, If you have other questions.

Regards,
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.
0
Hari
Top achievements
Rank 1
answered on 11 Jun 2009, 12:22 PM
Hi Jack,

Thanks for your quick response. I tried with your code.It is working fine, But When I test in different resolution, The last record is not displaying completely. The bottom border line of the last row of the child view is not displaying.

Can you provide me the generalized solution for any resolution?
For Example,
Some thing like below:
e.ChildRow.MaxHeight =  (gridRowheight * no.of records to be displayed)


Thanks
Hari
0
Boryana
Telerik team
answered on 12 Jun 2009, 12:18 PM
Hi Hari,

Please, consider the following code snippet:

        void radGridView1_ChildViewExpanded(object sender, Telerik.WinControls.UI.ChildViewExpandedEventArgs e) 
        { 
           if (e.IsExpanded) 
           { 
               e.ChildRow.Height = CalcHeight(e.ChildViewInfo); 
           } 
        } 
 
        private int CalcHeight(GridViewInfo viewInfo) 
        { 
            int height = 0; 
            int i = 0; 
            foreach (GridViewDataRowInfo rowInfo in viewInfo.Rows) 
            { 
                if (i < 5) 
                { 
                    height += rowInfo.GetActualHeight(radGridView1.GridElement); 
                    if (rowInfo.IsExpanded) 
                    { 
                        height += CalcHeight(rowInfo.ChildRow.ChildViewInfo); 
                    } 
                    i++; 
                } 
            } 
            if (viewInfo.ViewTemplate.ShowColumnHeaders) 
            { 
                height += viewInfo.TableHeaderRow.GetActualHeight(radGridView1.GridElement); 
            } 
            if (viewInfo.ViewTemplate.EnableFiltering) 
            { 
                height += viewInfo.TableFilteringRow.GetActualHeight(radGridView1.GridElement); 
            } 
            if (viewInfo.ViewTemplate.AllowAddNewRow) 
            { 
                height += viewInfo.TableAddNewRow.GetActualHeight(radGridView1.GridElement); 
            } 
                    //horizontal scrollbar 
                    height += 20; 
                    // vertical padding 
                    height += 20; 
            return height; 
        } 

In this example, CalcHeight function calculates the height of the second level of the RadGridView hierarchy. It takes into consideration the height of every element, such as filter row, horizontal scrollbar, vertical padding, etc. By setting value to (int)i variable, you can control the number of displayed rows. Please, do not forget to subscribe to ChildViewExpanded event.

I hope this helps. Please, let me know if you have further questions. 

All the best,
Boryana
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.
0
Hari
Top achievements
Rank 1
answered on 15 Jun 2009, 01:02 PM
Hi Boryana,

Thank you for your valuable  solution. I could able to achieve the required functionality with little modifications.
I have changed 'height' variable value to -2. It is working fine for me.


Thanks
Hari
Tags
GridView
Asked by
Hari
Top achievements
Rank 1
Answers by
Jack
Telerik team
Hari
Top achievements
Rank 1
Boryana
Telerik team
Share this question
or