Hi Martin,Thank you for using Syncfusion controls.We need some information about your requirement. Can you please provide below details?1. How do you load the SfDataGrid second time?2. Did you change the DataSource or are you using serialization approach?It will be helpful for us to check on it and provide you the solution at the earliest.Regards,Susmitha S
List<Group> expandedGroups = null;
List<string> columnName = null;
DataTable employeeCollection; public Form1()
{
InitializeComponent();
expandedGroups = new List<Group>();
columnName = new List<string>();
this.sfDataGrid1.AutoGenerateColumns = true;
var table = this.GetDataTable();
sfDataGrid1.DataSource = table;
this.sfDataGrid1.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "CustomerID" });
this.sfDataGrid1.ExpandAllGroup();
this.sfDataGrid1.DataSourceChanged += SfDataGrid1_DataSourceChanged;
}
private void SfDataGrid1_DataSourceChanged(object sender, Syncfusion.WinForms.DataGrid.Events.DataSourceChangedEventArgs e)
{
sfDataGrid1.BeginInvoke(new Action(() =>
{
if (e.NewValue !=null && columnName.Count > 0)
{
foreach (var col in columnName)
{
this.sfDataGrid1.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = col });
}
if (sfDataGrid1.View.TopLevelGroup != null)
{
foreach (Group group in sfDataGrid1.View.TopLevelGroup.Groups)
{
var isExpandGroup = group;
var key = expandedGroups.FirstOrDefault(colu => colu.Key.ToString() == isExpandGroup.Key.ToString());
do
{
if (key != null)
sfDataGrid1.ExpandGroup(isExpandGroup);
if (isExpandGroup.Groups != null)
{
isExpandGroup = isExpandGroup.Groups[0];
key = expandedGroups.FirstOrDefault(col => col.Groups[0].Key.ToString() == group.Groups[0].Key.ToString());
}
else
isExpandGroup = null;
} while (isExpandGroup != null);
}
}
}
}));
}
private void button1_Click(object sender, EventArgs e)
{
var groups = sfDataGrid1.View.TopLevelGroup.Groups;
foreach (Group group in groups)
{
if (group.IsExpanded)
expandedGroups.Add(group);
}
foreach (GroupColumnDescription groupColumnDescriptions in sfDataGrid1.GroupColumnDescriptions)
columnName.Add(groupColumnDescriptions.ColumnName);
this.sfDataGrid1.DataSource = GetDataTable1();
} |