Gridview Custom Hierarchy

4 posts, 1 answers
  1. Markus Giera
    Markus Giera avatar
    3 posts
    Member since:
    Mar 2010

    Posted 06 Apr 2010 Link to this post

    Dear Telerik users

    I've got two questions:

    1. Is it possible in "Winforms Gridview" to have a custom hierarchy as shown in the wpf example: http://demos.telerik.com/wpf/?GridView/Hierarchy/CustomHierarchy ?
    or in Silverlight http://demos.telerik.com/silverlight/#GridView/Hierarchy/CustomHierarchy
    I've got a list of custom objects sometimes containing a collection of objects. So I want the "+" button only to display if the objects contains subobjects.

    2. If not, is it possible to hide the "+" button if a row's GetChildrows returns 0 childs? (by cellformatting?)

    Greets

    Markus

  2. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 08 Apr 2010 Link to this post

    Hello Markus Giera,

    RadGridView for Winforms does not support custom hierarchy (yet), but you can achieve similar behavior with the presented API of RadGridView.

    You need to check that a specified row has child rows. Also, as you mentioned you need to subscribe for the ViewCellFormatting event where you can hide the plus-minus element. Finally you have to prevent from expanding rows that don't have child rows in the ChildViewExpanding event. You can use the following code snippet:

    private void radGridView_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridGroupExpanderCellElement cellElement = e.CellElement as GridGroupExpanderCellElement;
        GridViewDataRowInfo dataRow = e.CellElement.RowInfo as GridViewDataRowInfo;
     
        if (cellElement != null && dataRow != null)
        {
            bool hasChildRows = false;
     
            if (dataRow.Tag == null)
            {
                hasChildRows = this.HasChildRows(dataRow);
                dataRow.Tag = hasChildRows;
            }
            else
            {
                hasChildRows = (bool)dataRow.Tag;
            }
     
            if (hasChildRows)
            {
                cellElement.ResetValue(GridGroupExpanderCellElement.SignStyleProperty, ValueResetFlags.Local);
            }
            else
            {
                cellElement.SignStyle = GridGroupExpanderCellElement.SignStyles.Image;
            }
        }
    }
     
    private void radGridView_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e)
    {
        GridViewDataRowInfo dataRow = e.ParentRow;
     
        bool hasChildRows = false;
     
        if (dataRow.Tag == null)
        {
            hasChildRows = this.HasChildRows(dataRow);
        }
        else
        {
            hasChildRows = (bool)dataRow.Tag;
        }
     
        e.Cancel = !hasChildRows;
        dataRow.Tag = hasChildRows;
    }

    If you need further assistance do not hesitate to write us back.
     

    All the best,
    Svett
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Pixie
    Pixie avatar
    1 posts
    Member since:
    May 2013

    Posted 09 May 2013 Link to this post

    What is the current way to do this? SignStyleProperty and SignStyle don't seem to exist any more.
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    717 posts

    Posted 14 May 2013 Link to this post

    Hi Pixie,

    Thank you for writing.

    The cell element now contains an expander element and these properties concern this inner element. Given that the code should look like this:
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridGroupExpanderCellElement cellElement = e.CellElement as GridGroupExpanderCellElement;
        GridViewDataRowInfo dataRow = e.CellElement.RowInfo as GridViewDataRowInfo;
     
        if (cellElement != null && dataRow != null)
        {
            bool hasChildRows = false;
     
            if (dataRow.Tag == null)
            {
                hasChildRows = this.HasChildRows(dataRow);
                dataRow.Tag = hasChildRows;
            }
            else
            {
                hasChildRows = (bool)dataRow.Tag;
            }
     
            if (hasChildRows)
            {
                cellElement.Expander.ResetValue(GridExpanderItem.SignStyleProperty, ValueResetFlags.Local);
            }
            else
            {
                cellElement.Expander.SignStyle = SignStyles.Image;
            }
        }
    }

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Greetings,
    Ivan Petrov
    the Telerik team
    RadChart for WinForms is obsolete. Now what?
Back to Top