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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridGroupingControl selected rows cache

Thread ID:

Created:

Updated:

Platform:

Replies:

127577 Nov 24,2016 01:56 PM UTC Nov 25,2016 08:45 AM UTC Windows Forms 1
loading
Tags: GridGroupingControl
eldad weissr
Asked On November 24, 2016 01:56 PM UTC

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 :)

Piruthiviraj Malaimelraj [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;