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 and SelectedRecordsChanging

Hello,

I am using the GridGroupingControl bound to a custom object collection and I am attempting to use the SelectedRecordsChanging event to provider the user with the chance to cancel the record change and remain on the currently selected record. I have run into some confusing behavior and would like some assistance.

I have implemented the SelectedRecordsChanging event with a dialog prompt to allow the user to continue with the record change by clicking OK (and thus lose any changes they have made) or by clicking Cancel and allowing the user to remain on the currently selected record. If the user opts to cancel, I set "e.Cancel = true" on the SelectedRecordsChangedEventArgs.

Unfortunately, this is not providing the desired behavior. I've found that when I choose to cancel the change, the SelectedRecordsChanging event is fired three more times (for a total of four times). The first time the "e.Action == SelectedRecordsChangedType.Reset", and the remaining events have "e.Action == SelectedRecordsChangedType.Added". After the last event, the originally selected record remains highlighted, but the CurrentCell moves to the new, un-highlighted record.

What is the proper way to initialize the grid and handle these events? I have the following properties set on my grid:

grid.TableOptions.AllowSelection = GridSelectionFlags.None;
grid.TableOptions.ListBoxSelectionMode = SelectionMode.One;

but the grid does not behave as I would expect it to.

Any help or suggestions are appreciated.

11 Replies

AD Administrator Syncfusion Team December 15, 2006 04:25 AM UTC

Hi John,

Try this code to cancel the record selection in a Grid.

DialogResult result;
private void gridGroupingControl1_SelectedRecordsChanging(object sender, SelectedRecordsChangedEventArgs e)
{
if( e.Action == Syncfusion.Grouping.SelectedRecordsChangedType.Reset)
result = MessageBox.Show("Allow the Record Selection Changes","Selections",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
e.Cancel = result == DialogResult.No? true : false;
}

Best Regards,
Haneef


AD Administrator Syncfusion Team December 15, 2006 04:26 PM UTC

Hi Haneef,

I have implemented the suggested method, but it still is not providing the desired behavior. When selecting "No" from the dialog box, the new row is highlighted in spite of the "e.Cancel = true"; at this point, both the previous row and selected row are highlighted. The CurrentCell has moved to the new selection, but the grid disregards the command to cancel the event.

Any ideas what else could be going on?

Thanks for your continued assistance.

>Hi John,

Try this code to cancel the record selection in a Grid.

DialogResult result;
private void gridGroupingControl1_SelectedRecordsChanging(object sender, SelectedRecordsChangedEventArgs e)
{
if( e.Action == Syncfusion.Grouping.SelectedRecordsChangedType.Reset)
result = MessageBox.Show("Allow the Record Selection Changes","Selections",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
e.Cancel = result == DialogResult.No? true : false;
}

Best Regards,
Haneef


AD Administrator Syncfusion Team December 18, 2006 07:11 AM UTC

Hi John,

Please try the attached sample and let me know if you are looking for something different.
GroupingSelectedRecords.zip

Best Regards,
Haneef


AD Administrator Syncfusion Team February 14, 2007 04:49 PM UTC

Hi Haneef,

This sample does not produce the desired results.

If you select a new record and click "yes" to allow the change, the grid behaves as it should (new record is highlighted, current cell is properly highlighted, etc.).

However, if you select a new record and click "no" to prevent the selection change, the record which was previously highlighted remains highlighted, but the current cell moves to the row for which selection was attempted.

What needs to be done to ensure that the CurrentCell remains on the selected record when the choice to cancel the selection change is made?

Thanks for your continued assistance.

>Hi John,

Please try the attached sample and let me know if you are looking for something different.
GroupingSelectedRecords.zip

Best Regards,
Haneef


AD Administrator Syncfusion Team February 14, 2007 09:56 PM UTC

Hi John,

One way you can do this by handling the CurrentRecordContextChange event of the grid and set e.Cancel to new value( it depends on the MessageBox user input). Please refer to the attached sample for implementation.

sample : GroupingSelectedRecords.zip


Best regards,
Haneef


AD Administrator Syncfusion Team February 15, 2007 05:39 PM UTC

Hi Haneef,

The sample that you provided performs as required.

Thanks for your assistance!

>Hi John,

One way you can do this by handling the CurrentRecordContextChange event of the grid and set e.Cancel to new value( it depends on the MessageBox user input). Please refer to the attached sample for implementation.

sample : GroupingSelectedRecords.zip


Best regards,
Haneef


PN Phani N August 28, 2009 03:12 PM UTC

Thanks Rajadurai for your sample. I guess I had over-complicated my case. Can you please provide a simple sample of how to cancel the selected record change based on user's input? Whatever I do I seem to cause the currentcell or the current row header to move. I don't want any sort of movement if the user says so.

Thanks for your help.


PN Phani N August 28, 2009 03:13 PM UTC

Posted in the wrong thread. Please ignore my previous post.


RC Rajadurai C Syncfusion Team September 7, 2009 12:41 PM UTC

Hi Phani,

Thanks for your update.

The solution for the query posted in last update has been updated in the following forum thread.
http://www.syncfusion.com/support/forums/grid-aspnet/89517

Please refer to it.

Regards,
Rajadurai


ML MARIA LEA FE MANGAOANG June 15, 2016 08:44 AM UTC

Hello I  have the same problem, can I also have the sample? When I tried to click the link, it is no longer available


AS Amresh S Syncfusion Team June 16, 2016 02:07 PM UTC

Hi Maria, 
 
Thank you for using Syncfusion products. 
 
In order to validate the current cell with desired set of values , you can use the TableControlCurrentCellAcceptedChanges event to validate the entered cell value. Here we have provided the sample in which the changes done in a cell can be allowed or rejected based upon the user input. Please refer to the following code snippet and the attached sample. 
 
CodeSnippet: 
// Trigger the required event. 
this.gridGroupingControl1.TableControlCurrentCellAcceptedChanges += new GridTableControlCancelEventHandler(gridGroupingControl1_TableControlCurrentCellAcceptedChanges); 
 
void gridGroupingControl1_TableControlCurrentCellAcceptedChanges(object sender, GridTableControlCancelEventArgs e) 
{ 
     DialogResult result; 
     result = MessageBox.Show("Allow the Record Selection Changes", "Selections", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 
     if (result == System.Windows.Forms.DialogResult.No)                
    { 
        e.Inner.Cancel = true; 
        e.TableControl.CurrentCell.Deactivate(true); 
     } 
} 
 
Sample: 
 
Regards, 
Amresh S. 


Loader.
Live Chat Icon For mobile
Up arrow icon