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

Minimizing parent hierarchy when child is selected

2 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Casey
Top achievements
Rank 1
Casey asked on 14 Jun 2011, 06:03 PM
Is there a way to minimize the parent hierarchy when a child is selected? Our users want only the header of the parent record(s) to be displayed without showing the rest of the rows for that hierarchy level.

For example:
We want to not show the rows for Category 2 and Category 3 when Category 1's children are displayed.

 

  1. Category 1
    1. Category 1a
    2. Category 1b
  2. Category 2
  3. Category 3

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jun 2011, 07:10 AM
Hello Casey,

Try the following code snippet in ItemCommand event to hide parent when child is selected.

C#:
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
        if (e.CommandName == RadGrid.ExpandCollapseCommandName)
        {
            GridDataItem currentItem = (GridDataItem)e.Item;
            if (!currentItem.Expanded)
            {
                int currentRowIndex = currentItem.ItemIndex;
                foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
                {
                    if (currentRowIndex != item.ItemIndex)
                        item.Visible = false;                                  
                }
            }
            else
            {
                foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
                {
                    item.Visible = true;
                      }
                }
         }
  }

Thanks,
Princy.
0
Casey
Top achievements
Rank 1
answered on 01 Aug 2011, 03:45 PM
Hi Princy,

This worked great for the default level of hierarchy but not for subsequent levels of hierarchy. The data structure I am using has a self referencing hierarchy. Is there a way to loop through the rows of the selected hierarchy level?

  1. Category 1
    1. Category 1a
      1. Category 1a1
      2. Category 1a2
    2. Category 1b
      1. Category 2a1
  2. Category 2
  3. Category 3
Tags
Grid
Asked by
Casey
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Casey
Top achievements
Rank 1
Share this question
or