We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridGroupingControl selected rows cache

Hi,

I have two questions regarding the GridGroupingControl selected rows cache, I've created a simple project and used Datatable that is the datasource of the GridGroupingControl.

1. After performing a sort by clicking a column header the view is focusing on the current cell/row, is there any way to disable it and keep the current first displayed row index?
2. If i want to update the datasource, is there any way to maintain the selected rows and keep them in the new view?

Thanks in advance :)

1 Reply

PM Piruthiviraj Malaimelraj Syncfusion Team November 25, 2016 08:45 AM UTC

Hi Eldad, 

Thanks for your interest in Syncfusion products. 

Query 
Response 
 
 
 
 
 
 
1. After performing a sort by clicking a column header the view is focusing on the current cell/row, is there any way to disable it and keep the current first displayed row index? 
In order to change the current cell focus when sorting the columns, SortedColumns.Changed event can be used. In that event , the current cell has been changed by using MoveTo method. Please make use of the below code, 

Code example: 
this.gridGroupingControl1.TableDescriptor.SortedColumns.Changed += SortedColumns_Changed; 
 
//Change the current cell to first row while sorting the records. 
void SortedColumns_Changed(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e) 
{ 
    GridCurrentCell currentCell = this.gridGroupingControl1.TableControl.CurrentCell; 
    if (currentCell != null) 
    { 
        this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(this.gridGroupingControl1.TableControl.TopRowIndex, currentCell.ColIndex, GridSetCurrentCellOptions.SetFocus); 
    } 
} 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2. If i want to update the datasource, is there any way to maintain the selected rows and keep them in the new view? 
In order to maintain the selected records collection, XmlSerialization support can be used. You can save the selected records as xml file and initialize that xml file to grid when datasource has changed. Please make use of the below code, 

Code example: 
//XML Serialization. 
List<GridSelectedRecordsCollection> SelectedRecordsList = new List<GridSelectedRecordsCollection>(); 
 
foreach (SelectedRecord record in this.gridGroupingControl1.Table.SelectedRecords) 
{ 
    SelectedRecordsList.Add(new GridSelectedRecordsCollection() { RecordID = this.gridGroupingControl1.Table.Records.IndexOf(record.Record) }); 
} 
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<GridSelectedRecordsCollection>)); 
XmlTextWriter xmlWriter = new XmlTextWriter("SelectedRecords.xml", System.Text.Encoding.UTF8); 
xmlSerializer.Serialize(xmlWriter, SelectedRecordsList); 
xmlWriter.Close(); 
 
this.gridGroupingControl1.DataSource = null; 
SelectedRecordsList.Clear(); 
 
//XML De-serialization 
XmlReader xr = new XmlTextReader("SelectedRecords.xml"); 
XmlSerializer serializer = new XmlSerializer(typeof(List<GridSelectedRecordsCollection>)); 
SelectedRecordsList = (List<GridSelectedRecordsCollection>)serializer.Deserialize(xr); 
 
this.gridGroupingControl1.DataSource = GetTable(); 
 
foreach (GridSelectedRecordsCollection record in SelectedRecordsList) 
{ 
    this.gridGroupingControl1.Table.SelectedRecords.Add(this.gridGroupingControl1.Table.Records[record.RecordID]); 
} 
xr.Close();  

Note: 
The selected records cannot be serialized directly into xml file. It can be achieved by serialized the index of the selected records. 

Sample link: 

Regards, 
Piruthiviraj

Loader.
Up arrow icon