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

Gridview Custom Hierarchy

3 Answers 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Markus Giera
Top achievements
Rank 1
Markus Giera asked on 06 Apr 2010, 08:11 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 08 Apr 2010, 04:33 PM
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.
0
Pixie
Top achievements
Rank 1
answered on 10 May 2013, 02:01 AM
What is the current way to do this? SignStyleProperty and SignStyle don't seem to exist any more.
0
Ivan Petrov
Telerik team
answered on 14 May 2013, 04:23 PM
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?
Tags
GridView
Asked by
Markus Giera
Top achievements
Rank 1
Answers by
Svett
Telerik team
Pixie
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or