0

I am trying to implement Collapse All / Expand ALL button on a Janus Grid in C# but there is no point in showing Collapse ALL when there is nothing to collapse!

So i need a way to find out if there is any row at some level is NOT expanded so that i can show and enable the Expand ALL button.

I am hoping for a way other that iterating down through all the rows and verifying if some random child row is not expanded.

Thank you!

hunter986
  • 1
  • 2

1 Answers1

0

To my knowledge there is no such built in method. My suggestion if it is important that you don't use recursion is to utlize the RowCollapsed and RowExpanded events in conjuction with a HashSet<GridEXRow> to register and unregister rows that get expanded/collapsed.

public class ...
{
    ...
    HashSet<GridEXRow> expandedRows = new HashSet<GridEXRow>();

    public bool IsExpanded
    {
        get { return expandedRows.Count > 0; }
    }
    ...

    private void gridEX_RowCollapsed(object sender, Janus.Windows.GridEX.RowActionEventArgs e)
    {
        expandedRows.Remove(e.Row);
    }

    private void gridEXLocation_RowExpanded(object sender, Janus.Windows.GridEX.RowActionEventArgs e)
    {
        expandedRows.Add(e.Row);
    }
}

Note that using this method there could be a performance hit when you Expand all (all rows added to expandedRows) and collapse. Collapse all would clear expandedRows, however when collapsing all you would still trigger RowCollapsed for each row e.g. theres no such shortcut as doing expandedRows.Clear(); without first removing the event and then putting it back again.

NLindbom
  • 498
  • 6
  • 12