Child Grid Vertical Size

10 posts, 1 answers
  1. George
    George avatar
    62 posts
    Member since:
    Sep 2008

    Posted 22 May 2009 Link to this post

    Hi All,

    I am trying to set a maximum vertical size to be displayed for a child grid at all times, the vertical scroll bar of the child grid enabled in autohide mode in order to be able to see the rest of the rows. By vertical size I mean how many rows to be displayed at any given time in the child grid, and not the vertical height of each individual row. Unfortunately, although I have tried, I cannot find a reference on how to implement this feature. Any suggestions will be highly appreciated.

    Kind Regards,


    George
  2. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 25 May 2009 Link to this post

    Hello George,

    By default the child view height is determined automatically. I admit, that currently our sizing algorithm is not the best. We will improve it in our next release. You can control this size manually by setting the Height property of the corresponding GridViewDetailsRowInfo. This can be done when handling the ChildViewExpanded event. Here is a sample:

    void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e) 
    {     
        e.ChildRow.Height = 400; 

    You can use the following method to calculate the size needed to show all child view rows:

    private int CalcHeight(GridViewInfo viewInfo) 
        int height = 0; 
        foreach (GridViewDataRowInfo rowInfo in viewInfo.Rows) { 
            height += rowInfo.GetActualHeight(RadGridView1.GridElement); 
            if (rowInfo.IsExpanded) { 
                height += CalcHeight(rowInfo.ChildRow.ChildViewInfo); 
            } 
        } 
        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); 
        } 
        if ((viewInfo.GridViewElement != null)) { 
            if (viewInfo.GridViewElement.HScrollBar.Visibility == ElementVisibility.Visible) { 
                height += 20; 
            } 
        } 
        return height; 

    And the code below shows how to use it when handling the ChildViewExpanded event:

    private void RadGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e) 
        if (e.IsExpanded) { 
            if ((e.ParentRow.ViewInfo.ParentRow != null)) { 
                int height = CalcHeight(e.ParentRow.ViewInfo); 
                if (e.ParentRow.ViewInfo.ParentRow.ChildRow.Height < height) { 
                    e.ChildRow.Tag = e.ParentRow.ViewInfo.ParentRow.ChildRow.Height; 
                    e.ParentRow.ViewInfo.ParentRow.ChildRow.Tag = e.ParentRow.ViewInfo.ParentRow.ChildRow.Height; 
                    e.ParentRow.ViewInfo.ParentRow.ChildRow.Height = height; 
                } 
            } 
        } 
        else if ((e.ParentRow != null)) { 
            if ((e.ParentRow.ViewInfo.ParentRow != null)) { 
                if ((e.ParentRow.ViewInfo.ParentRow.ChildRow.Tag != null)) { 
                    e.ParentRow.ViewInfo.ParentRow.ChildRow.Height = (int)e.ParentRow.ViewInfo.ParentRow.ChildRow.Tag; 
                } 
            } 
        } 

    I hope this helps. If you have any additional questions, feel free to ask.

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. George
    George avatar
    62 posts
    Member since:
    Sep 2008

    Posted 25 May 2009 Link to this post

    Thank you Jack for your prompt reply, unfortunately however the first suggested line of code in the ChildViewExpanded event thraws an unhandled exception if coded in visual basic. Seems a check is required forst to make sure its not nothing. Like

    if isnothing e.childrow then exit sub.

    Otherwise it seems to work.

    Regards,

    George
  5. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 25 May 2009 Link to this post

    Hello George,

    You are correct. I missed to add this condition. I am glad to hear that you solved this issue. If you have any other questions, please don't hesitate to write us back.

    Best wishes,
    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.
  6. Tim DiPaula
    Tim DiPaula avatar
    16 posts
    Member since:
    Jul 2009

    Posted 15 Oct 2009 Link to this post

    I modified the other code examples to get this to work correctly for nested grids at any level.  Set the RadGrivView.ChildViewExpanded event handler to call RadGridView_ChildViewExpanded and they grids with expanded and contract correctly.

     private void RadGridView_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e) 
            { 
                if (e.IsExpanded) 
                { 
                    //Get the currently expanding row height 
                    if (e.ParentRow.ViewInfo != null
                    { 
                        int height = CalcHeight((RadGridView)sender, e.ChildViewInfo); 
                        e.ChildRow.Height = height; 
     
                    } 
                    if ((e.ParentRow.ViewInfo.ParentRow != null)) 
                    { 
                        int height = CalcHeight((RadGridView)sender, e.ParentRow.ViewInfo); 
     
                        if (e.ParentRow.ViewInfo.ParentRow.ChildRow.Height < height) 
                        { 
                            e.ChildRow.Tag = e.ParentRow.ViewInfo.ParentRow.ChildRow.Height; 
                            e.ParentRow.ViewInfo.ParentRow.ChildRow.Tag = e.ParentRow.ViewInfo.ParentRow.ChildRow.Height; 
                            e.ParentRow.ViewInfo.ParentRow.ChildRow.Height = height; 
                        } 
     
                    } 
                } 
                else if ((e.ParentRow.ViewInfo != null)) 
                { 
                    int height = CalcHeight((RadGridView)sender, e.ParentRow.ViewInfo); 
     
                    if (e.ParentRow.ViewInfo.ParentRow != null
                    { 
                        e.ParentRow.ViewInfo.ParentRow.ChildRow.Height = height; 
                    }              
                } 
            } 
            private int CalcHeight(RadGridView gridView, GridViewInfo viewInfo) 
            { 
                int height = 0; 
     
                if (viewInfo.Rows != null
                { 
                    foreach (GridViewDataRowInfo rowInfo in viewInfo.Rows) 
                    { 
                        int actualHeight = rowInfo.GetActualHeight(gridView.GridElement); 
                        if (actualHeight < 25) 
                            actualHeight = 25; 
     
                        height += actualHeight; 
                        if (rowInfo.IsExpanded) 
                        { 
                            height += CalcHeight(gridView, rowInfo.ChildRow.ChildViewInfo); 
                        } 
                    } 
                } 
     
                if (viewInfo.ViewTemplate.ShowColumnHeaders) 
                { 
                    int tableHeaderRowHeight = viewInfo.TableHeaderRow.GetActualHeight(gridView.GridElement); 
                    if (tableHeaderRowHeight < 50) 
                        tableHeaderRowHeight = 50; 
     
                    height += tableHeaderRowHeight; 
                } 
                if (viewInfo.ViewTemplate.EnableFiltering) 
                { 
                    height += viewInfo.TableFilteringRow.GetActualHeight(gridView.GridElement); 
                } 
                if (viewInfo.ViewTemplate.AllowAddNewRow) 
                { 
                    height += viewInfo.TableAddNewRow.GetActualHeight(gridView.GridElement); 
                } 
                if ((viewInfo.GridViewElement != null)) 
                { 
                    if (viewInfo.GridViewElement.HScrollBar.Visibility == Telerik.WinControls.ElementVisibility.Visible) 
                    { 
                        height += 20; 
                    } 
                } 
                return height; 
            } 

  7. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 19 Oct 2009 Link to this post

    Hi Tim,

    Thank you for sharing this solution with the community. In our upcoming release we will present a new scrolling mechanism that solves the issue, however I think this code will be useful for our customers. I updated your points accordingly.

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Tom Chien
    Tom Chien avatar
    125 posts
    Member since:
    Jun 2009

    Posted 20 Oct 2009 Link to this post

    Check out the Q3 2009 Beta.  The Vertical Scroll Bar per each expanded ChildGridViewTemplate has been replaced by a single Vertical Scroll Bar at the MasterGridViewTemplate level that now also scrolls gracefully and smoothly through expanded ChildGridViewTemplates vs. clumsily skipping over them and totally disorienting the user.  This is SO much better!  I'm glad my users never saw that.  They would've had a cow.  Of course to have a single Vertical Scroll Bar also means that all expanded ChildGridViewTemplates always have to have a visible height that shows all its Rows so like Jack said this workaround will no longer be needed.
  9. Darren Wright
    Darren Wright avatar
    1 posts
    Member since:
    Jul 2009

    Posted 10 Nov 2009 Link to this post

    I was looking forward for this realease and removal of the work around described in this post from my code. The single scrollbar seems to be working fine but I am still experiencing problems with:
    1. Authomatical sizing of the grid. I have a sothisiticated, multilevel folder structure authomatically generated from the DataSet composed on N tables connected with relations (actually very closely resembling the file system structure) and opening third level folder doesn't seem to resize the table. My folders from deeper levels are not visible.
    2. The option to resize the grid manually dissapeared therefore my users are unable to resize the tables to see the nested levels.

    The only thing I did was substitution of the assemblies and the removal of the resizing event.

    Any suggestions where to look for the solution?

    Regards,
    Adam
  10. George
    George avatar
    62 posts
    Member since:
    Sep 2008

    Posted 12 Nov 2009 Link to this post

    Hi all, I am returning to this post since I initially started it. I have just upgraded to Q3 version of the control and now my initial problem has returned since a vertical scroll bar on the childgrid is not any more supported. Once again I repeat my task:

    A childgrid might have for example 100 records to display. I do not want to display all of them when the master record is expanded since this significantly deterriorates the overall visibility and usability of the whole grid. From the available 100 child records I want to display for example only 5 at each time and have a verticall scroll bar next to the childgrid to scroll through the rest of the records. How can I accomplish this task in the Q3 version?

    P.S. I had to giveup the previous version I used and upgrade to Q3 because I had another issue with the border thickness of radforms that was resolved in Q3.

    Regards,

    George
  11. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 12 Nov 2009 Link to this post

    Hi guys,

    you can turn on the nested scrollbars by setting the UseScrollbarsInHierarchy property to true.

    @Darren: Please, send us your application so we can test your case and address the issue.

    @George: Enable the scrollbars in hierarchy by setting UseScrollbarsInHierarchy to true and handle the ChildViewExpanded event to limit the child view height. Please consider the sample below:

    void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e)
    {
        e.ChildRow.Height = 200;
    }

    I hope this helps. If you need further assistance, don't hesitate to write me.
     

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WinForms is Visual Studio 2017 Ready