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

SelectionChanging: Modify AddedItems

1 Answer 184 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 11 May 2017, 06:58 AM

Hello!

I want not to completely cancel a SelectionChanging event in the GridView but instead just modify AddedItems (remove some of them that are not fitting to the previously selected items). It should look like a normal selection via drag and drop, just with some unselected items in beetween.

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 15 May 2017, 09:57 PM
Hi Alexander,

To achieve your requirement you can use the SelectionChanged event of RadGridView. In the event handler you can check what elements from the e.AddedItems collection should not be selected and remove them from the SelectedItems collection of RadGridView. For example:
private void gridView_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
{
    var gridView = (RadGridView)sender;
    var selectedItems = e.AddedItems;
    foreach (MyGridItemModel item in selectedItems)
    {
        if (!item.CanSelect)
        {
            gridView.SelectedItems.Remove(item);
        }
    }
}
You can check this approach shown in the attached project. I hope this helps.

Regards,
Martin Ivanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or