Posted 18 January 2018, 7:11 am EST
Hello,
There is no direct approach for storing the states. However, we can take help of groupRow.Group.Name property that gives us the name of the group. We can then store these along with the group level in some list and while restoring match them.
I have created a sample code snippet for this, please refer to the following:
private void SaveExpandedRows()
{
DefineRows.Clear();
for (int i = 0; i <= _flex.Rows.Count - 1; i++)
{
if (_flex.Rows[i] is GroupRow)
{
if(((GroupRow)_flex.Rows[i]).IsCollapsed == true)
{
this.DefineRows.Add(((GroupRow)_flex.Rows[i]).Group.Name.ToString()+"," + ((GroupRow)_flex.Rows[i]).Level.ToString()+","+"Collapsed");
}
else
{
this.DefineRows.Add(((GroupRow)_flex.Rows[i]).Group.Name.ToString() + "," + ((GroupRow)_flex.Rows[i]).Level.ToString()+","+"Expanded");
}
}
}
}
private void RestoreExpandedRows()
{
if(DefineRows.Count!=0 )
{
for (int i = 0; i <= _flex.Rows.Count - 1; i++)
{
if (_flex.Rows[i] is GroupRow)
{
int lastRow = _flex.Rows.Count - 1;
int row = 0;
List<List<String>> tags = new List<List<String>>();
foreach (string data in DefineRows)
{
List<string> subTags = data.Split(',').ToList<string>();
tags.Add(subTags);
}
while (row <= lastRow)
{
if (_flex.Rows[row] is GroupRow)
{
GroupRow gr = (GroupRow)_flex.Rows[row];
if (gr != null)
{
foreach (List<String> ls in tags)
{
if (gr.Level.ToString() == ls[1] && gr.Group.Name.ToString() == ls[0])
{
if (ls[2] == "Collapsed")
{
gr.IsCollapsed = true;
}
else
{
gr.IsCollapsed = false;
}
}
}
}
}
row = row + 1;
}
}
}
}
}
Hope this helps.
Regards,
Ruchir Agarwal