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

Restoring the SelectedRecord of a GGC (Record based selection)

My main issue is that our GridGroupingControl is set to refresh its data on a timer, I have already added code to preserve the state of the expanded/collapsed records, so that the GridGroupingControl LOOKS the same when data is refreshed. The problem is that if a user selects a row (or row in the one child table) and the data gets refreshed, the user’s selected record (or row) is gone. I have looked at some of the options in your forums, but neither will work for me.

I cannot use “Row based selection” where the ‘grid.tableOptions.AllowSelections’ is set to ‘GridSelectionFlags.Row’ because this does not allow for my GridGroupingControl to expand/collapse when I select a row. I do not think I can set the expanded/collapsed data using this type of selection. Also, I cannot seem to use the ‘grid.Table.SelectedRecords[]’ collection either.

I need to use “Record based selection” where I use the ‘SelectedRecords’ collection often. I also need to programmatically set the ‘IsExpanded’ property of a ‘SelectedRecord’ object. I use the ‘SelectedRecords’ collection throughout my Form. So, I tried to save the “SelectedRecord” object in the grid when my data gets refreshed - my sequence looks like this:

1) Save the ‘SelectedRecord’ object using this: _selectedRecord = grid.GetTable(…).SelectedRecords[0].Record;

2) Refresh the data …

3) Set the ‘SelectedRecord’ back to the grid using this: grid.GetTable(…).SelectedRecords.Add(_selectedRecord);

However, after I refresh my data, my “_selectedRecord” object is NULL and loses all of its data!


So, my ultimate question is this:

Which type of record selection do I need to use for my GridGroupingControl to enable me to expand/collapse data within my grid and get the selected record with one “child” table, as well as save any selected record when my GridGroupingControl is refreshed?


Thanks in advance!

4 Replies

HA haneefm Syncfusion Team July 16, 2007 08:11 PM UTC

Hi Dave,

Regarding refresh Issue:

You can try setting TableDirty and SummariesDirty properties to refresh the data in a grid.

groupingGrid.Table.TableDirty = true;
groupingGrid.Table.SummariesDirty = true;

TableDirty = true indicates to the engine that it needs to recategorize elements and refresh counters and summaries the next time it is painted or the the next you want to access a record or summary information.

Selection Types:

The GridGroupingControl has two types of selection mode.

Type 1: Row based selection
This selection support can be turned on by setting the grid.tableOptions.AllowSelections to something other than None. This selection functionality raises events like the grid.TableModel.SelectionChanging/Changed.

[c#]
this.gridGroupingControl1.TableControl.Selections.Add(GridRangeInfo.Row(3));

Type 2: Record based selection
This selection support is turned on by setting the grid.TableOptions.AllowSelections to None and setting the grid.TableOptions.ListBoxSelectionMode to something other than None.

[c#]
this.gridGroupingControl1.Table.SelectedRecords.Add(record);

Please refer to the following KB article for more details.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344

Best regards,
Haneef


DB Dave Busch July 18, 2007 02:00 PM UTC

Thanks Haneef,

I need to use Record Based Selection, so my issue is that I need to do this:

1) Save the ‘SelectedRecord’ object using this code:
_selectedRecord = grid.GetTable(tableName).SelectedRecords[0].Record;

2) Refresh the data in the GGC

3) Set the ‘SelectedRecord’ back to the grid using this code(??):
grid.GetTable(tableName).SelectedRecords.Add(_selectedRecord);


The problem is that the '_selectedRecord' variable is cleared (set to NULL) in Step #2. How can I "preserve" the selected record data during a refresh and then set the selected record back to the GGC after the refresh is done?


Thanks again :)
Dave Busch


>Hi Dave,

Regarding refresh Issue:

You can try setting TableDirty and SummariesDirty properties to refresh the data in a grid.

groupingGrid.Table.TableDirty = true;
groupingGrid.Table.SummariesDirty = true;

TableDirty = true indicates to the engine that it needs to recategorize elements and refresh counters and summaries the next time it is painted or the the next you want to access a record or summary information.

Selection Types:

The GridGroupingControl has two types of selection mode.

Type 1: Row based selection
This selection support can be turned on by setting the grid.tableOptions.AllowSelections to something other than None. This selection functionality raises events like the grid.TableModel.SelectionChanging/Changed.

[c#]
this.gridGroupingControl1.TableControl.Selections.Add(GridRangeInfo.Row(3));

Type 2: Record based selection
This selection support is turned on by setting the grid.TableOptions.AllowSelections to None and setting the grid.TableOptions.ListBoxSelectionMode to something other than None.

[c#]
this.gridGroupingControl1.Table.SelectedRecords.Add(record);

Please refer to the following KB article for more details.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344

Best regards,
Haneef


RA Rajagopal Syncfusion Team July 18, 2007 08:47 PM UTC

Hi Dave,

Instead of setting the SelectedRecord object(_selectedRecord) to null clear the SelectedRecords collection, when you refresh the data in GGC, using the code below in step #2.

grid.GetTable(tableName).SelectedRecords.Clear();

Then in step #3, reset the selectedrecord object back to the grid by adding it to the Table.SelectedRecords collection. Please refer the code below.

if (_selectedRecord != null)
{
grid.GetTable(tableName).SelectedRecords.Clear();
grid.GetTable(tableName).SelectedRecords.Add(_selectedRecord);
_selectedRecord.Record.SetCurrent();
}

Let me know if this helps.

Have a nice time.
Regards,
Rajagopal


DB Dave Busch July 19, 2007 02:59 AM UTC

Thank you so much for the prompt reply, Rajagopal. Unfortunately, I do not think I am making myself 100% clear. Here is what my code does:

1) Save the Selected Record:
_selectedRecord = ggc.GetTable(tableName).SelectedRecords[0].Record; //Works Fine

2) Refresh the data in the GGC:
ggc.DataSource = RefreshData(); //Automatically clears the ‘_selectedRecord’ object

3) Try and restore the Selected Record (which does not work):
ggc.GetTable(_tableName).SelectedRecords.Add(_selectedRecord); //Invalid - _selectedRecord is NULL


I believe I found a work around however:

I can loop through the records of the table and save the ‘Index’ of the selected one, and then restore it after my data is refreshed:

1) Save the selected Record:
foreach (Record rec in ggc.GetTable(tableName).Records)
{
if (rec.IsSelected())
{
_selectedRecordId = rec.GetSourceIndex();
break;
}
}


2) Refresh the data in the GGC

3) Restore the selected Record:
foreach (Record rec in ggc.GetTable(tableName).Records)
{
if (rec.GetSourceIndex() == _selectedRecordId)
{
ggc.GetTable(_tableName).SelectedRecords.Add(rec);
break;
}
}

Loader.
Live Chat Icon For mobile
Up arrow icon