This is a migrated thread and some comments may be shown as answers.

implementing SelectionChanging

3 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jean-Marc Schellings
Top achievements
Rank 1
Jean-Marc Schellings asked on 18 Aug 2009, 02:38 PM
Hello,

We would like to implement something like a SelectionChanging event (before the selection is changed) on the RadGridView.
The aim is to be able to decide wether the user can change the selection or not and cancel the action that made the selection to be changed (like when the user click on a row).

We cannot find such event in the RadGridView API.

We tried to place some event args Handled properties to true but without success, but we are not used with routed event handling.

Could anyone tell us how this could be done with the RadGridView ? an extension method ? managing mouse events deeper ?

Thank you

3 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 20 Aug 2009, 03:39 PM
Hello Jean-Marc Schellings,

There is one workaround that you can try - just subscribe to the SelectionChanged event and in the event handler decide if the new selection is valid and if not reverse the changes:

private bool isChanging = false;  
 
void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)  
{  
    if (isChanging)  
        return;  
 
    this.isChanging = true;  
 
    foreach (var item in e.AddedRecords)  
        this.RadGridView1.SelectedRecords.Remove(item);  
 
    foreach (var item in e.RemovedRecords)  
        this.RadGridView1.SelectedRecords.Add(item);  
 
    this.isChanging = false;  

For examples, this code does not allow any changes to the selection. Of course, you can implements your own selection validation logic inside the event handler.
Hope this helps.

We are also considering adding SelectionChanging event to RadGridView in the future.


Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sandi Markon
Top achievements
Rank 1
answered on 29 Mar 2010, 08:12 AM
Yes, we badly need this event! Please implement SelectionChanging event to RadGridView in the near future!

Best Regards,
0
Milan
Telerik team
answered on 29 Mar 2010, 08:27 AM
Hello Sandi Markon,

Thank you for your feedback. We would really appreciate it if you could spare some time to share how would you use the SelectionChanging event? I guess the primary use of this event would be to cancel selection changes but I am also interested if you expect to be able to modify the selection in that event? For example, if the event arguments expose RemovedItems and AddedItems properties should you be able to modify those collections or just use them as reference (read-only collections)?

Best wishes,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Jean-Marc Schellings
Top achievements
Rank 1
Answers by
Milan
Telerik team
Sandi Markon
Top achievements
Rank 1
Share this question
or