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

SelectionChanging?

17 Answers 276 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 10 Sep 2010, 01:48 PM
Hi!

I actually need to permit to an user to change of row only when some conditions have been met.

I've seen a "SelectionChanged", But with this it's too late, the row has already been changed.

So how can I catch this event and cancel it if I want it?

Thank you

17 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 13 Sep 2010, 09:01 AM
Hello Julien,

We already have this in our ToDo list. It is also in the public issue tracking system so you can login and vote for it here:
http://www.telerik.com/support/pits.aspx#/public/silverlight/2026

Thank you

Greetings,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 13 Sep 2010, 09:03 AM
Okay, but how can I handle my problem?

I see that the new functionality implementation is still not planned.

Edit: And it seems the PITS item is for silverlight
0
Veselin Vasilev
Telerik team
answered on 13 Sep 2010, 10:11 AM
Hello Julien,

Here is the workaround you can use:

Subscribe to the SelectionChanged event and define its handler as below:

private void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
    RadGridView grid = sender as RadGridView;
  
    if (grid.SelectedItems.Count > 0 && YOUR_CONDITION_HERE)
    {
        grid.SelectedItems.Remove(e.AddedItems[0]);
    }
}

Hope this helps.

Regards,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 13 Sep 2010, 10:17 AM
The problem is that my condition depend of a value on the previously CurrentItem , and because I've all my object binded to the CurrentItem.

More important, I need to watch my textboxes to see if one value has changed(this is one condition), and if I do this in the SelectionChanged event, values have already changed due to the binding and event have been thrown in all case.
0
Veselin Vasilev
Telerik team
answered on 14 Sep 2010, 08:47 AM
Hello Julien,

Is the CurrentItem synchronized with the SelectedItem in your case? You can check the value of the IsSynchronizedWithCurrentItem property of RadGridView.
You might set it to True to see if it works for your case.

All the best,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 14 Sep 2010, 08:55 AM
Unfortunately, they are in two different raddockingpanel, so they are bound by the code behind, otherwise I don't have any access to the radgridview, So they cannot be syncronized with each other.
0
Veselin Vasilev
Telerik team
answered on 14 Sep 2010, 09:05 AM
Hello Julien,

Maybe providing more information about your scenario will help us determine whether there is a solution that you can use before we introduce the new event.

Thanks

Regards,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 14 Sep 2010, 09:26 AM
The RadGrivew is used to browse a set of  rows, it contains a reduces list of fields of my rows.

In a different radDockingPanel, we have several TextBox/DatePicker/... that permits to edit the CurrentItem of the RadGridView. They are bound to the CurrentItem through the codebehind.

I need to save data on the server before changing rows, for this I need to know if there is some changes, so I've some "TextChanged" events on all my field, once I know that, I need to display a dialog that ask to save or cancel changes, or cancel the changement of "CurrentItem".

To know if my items have been modified, I found another way, I listen directly on the bound object event. 

Problems:
-When I'm changing row, it throw a "TextChanged" event[SOLVED by using the change listener directly on my objects]
-When I show the dialog box, fields have already changed of value
-I Cannot cancel easily a change
-If I restore the previous selected Item, it throw a new SelectionChanged event, so I come back again in my method, and it's begin to be hard to handle each possible SelectionChanged event
0
Veselin Vasilev
Telerik team
answered on 15 Sep 2010, 01:55 PM
Hello Julien,

You can combine your logic with the one I am attaching here.


Regards,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 15 Sep 2010, 02:17 PM
With your example:

-Wether you click on cancel or OK, you change of rows(and I've three possible action: "savechange and change row", "cancel change and change row", "Keep changes and don't change row", something like a "Save, Discard, Cancel".
-The dialog box is displayed on every line change, with or without a modification(Can be easily change with my INotifyPropertyChanged objects-> not a problem)
0
Veselin Vasilev
Telerik team
answered on 16 Sep 2010, 12:42 PM
Hello Julien,

To my regret I do not believe it is possible without having the SelectionChanging event introduced.

Sorry for the inconvenience.

Sincerely yours,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 16 Sep 2010, 01:28 PM
I really need a workaround for this problem, or a SelectionChanging event. I've to give a version of the programm in two weeks :/

Moreover, this item is the open PITS item that have the most number of vote in its category .
0
Veselin Vasilev
Telerik team
answered on 17 Sep 2010, 03:08 PM
Hello Julien,

Realistically, this feature will not be ready before Q3 - we will do our best to include in that major release.

You may need to revise your logic. Please check the project in this blog post - the business object implements the IEditableObject interface and handles easily Save and Cancel changes while not allowing the user to select another row in the gridview.

Regards,
Veselin Vasilev
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
0
Julien
Top achievements
Rank 1
answered on 20 Sep 2010, 07:10 AM
Hello,

When is planned the Q3 release? But it's only a small event, that you should already manage in your side. 

I've 40+ classes, with 10-20 properties by class, it will take a lot of time, and all my interfaces are bound directly to a properties of an object, not to the object directly so I don't think that these method will be called.
0
Accepted
Milan
Telerik team
answered on 21 Sep 2010, 09:18 AM
Hi Julien,

I understand your frustration but I am afraid that there are some cases which make the SelectionChanging event a bit more difficult to implement and those cases should be taken care of. 

In the mean time you can try yet another workaround. The idea is to handle selection manually by setting CanUserSelect to false and subscribing to MouseLeftButtonDown of the grid.

public MainWindow()
{
    InitializeComponent();
  
    this.playersGrid.CanUserSelect = false;
    this.playersGrid.SelectionChanged += 
        new EventHandler<SelectionChangeEventArgs>(playersGrid_SelectionChanged);
    this.playersGrid.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, 
        new MouseButtonEventHandler(OnMouseLeftDown), true);
}
  
private void OnMouseLeftDown(object sender, MouseButtonEventArgs e)
{
    FrameworkElement senderElement = e.OriginalSource as FrameworkElement;
    var parentRow = senderElement.ParentOfType<GridViewRow>();
  
    if (parentRow != null)
    {
        var result = MessageBox.Show("Save changes?", "Save or cancel?", MessageBoxButton.OKCancel);
  
        if (result == MessageBoxResult.OK)
        {
            // save data and make selection;
  
            parentRow.IsSelected = true;
        }
    }
}

That way you will be able to controls if selection is performed.

Hope this helps.


All the best,
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
0
Julien
Top achievements
Rank 1
answered on 21 Sep 2010, 02:27 PM
This is actually working :) Really a good news. Altough I'm not satisfied to have to manage myself click events, it's a great workaround, to let my customer work until your Q3.

Is this working also with RadTreeView? I've the same problem with them.

And you didn't answer to my question about availability date for the Q3 version.
0
Accepted
Tina Stancheva
Telerik team
answered on 23 Sep 2010, 01:35 PM

Hi Julien,

Q3 should be available sometime in mid November. In addition, we will release a beta several weeks before Q3.

In regards to RadTreeView you can handle the PreviewSelectionChanged() event of the Tree:

<telerik:RadTreeView x:Name="radTreeView1" IsDragDropEnabled="True"
         ItemTemplate="{StaticResource ItemTemplate}"
         PreviewSelectionChanged="radTreeView1_PreviewSelectionChanged"/>
private void radTreeView1_PreviewSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    //insert custom logic for canceling the selection
    if (cancelSelection)
        e.Handled = true;
}

Give it a try and let us know if it works for you.

All the best,
Tina Stancheva
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
Julien
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Julien
Top achievements
Rank 1
Milan
Telerik team
Tina Stancheva
Telerik team
Share this question
or