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

GridView and collection reorder, SelectedItem becomes null

4 Answers 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 15 Apr 2013, 09:16 PM
I am using MVVM pattern.  I have a RadGridView and have bound the ItemsSource to a collection and SelectedItem to an individual item in the VM.    This works, and I have some buttons to reorder the collection.  They call a command on the VM that moves the SelectedItem up or down in the collection.  This works fine but it appears that after the item gets moved, the SelectedItem becomes null.  My goal is to be able to select an item in the RadGridView and then click the "Move Up" button several times to move the item up in the collection.  Currently the experienced behavior is that I click the item and get one Move Up(or Down) before the SelectedItem becomes null and I am required to select an item to continue moving items.  I have put debug statements in both the SelectionChanged and SelectionChanging events on the RadGridView. 

Upon running my app, here is the order I see:

Event

SelectedItem

SelectionChanging

null

SelectionChanged

CorrectItem

Move method

CorrectItem

SelectionChanging CorrectItem
SelectionChanged  null

I even tried manually setting the SelectedItem in the VM after reordering it, but the reset to null appears to happen sometime after this. 
I have the latest version (2013.1.220.45)  installed and referenced in my project.
   Please let me know if something is unclear.

Thanks,
Chris

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 18 Apr 2013, 02:37 PM
Hi Chris,

May I ask you to share the code implementation for the "Move Up" button click (how do you move the item)?
  

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Chris
Top achievements
Rank 1
answered on 23 Apr 2013, 12:40 PM
Didie,

I created a sample application to demonstrate the behavior.  Then when I tested it, the up and down movement of items within the collection was working as expected.  I then added in the XAML properties I had applied to my RadGridView in my original project.  The problem resurfaced.  I narrowed it down to the IsFilteringAllowed="False" property.  Once I set this, the SelectedItem become null after the operation is performed.  I can submit the demo application if you would like.

Thanks,
Chris
0
Dimitrina
Telerik team
answered on 23 Apr 2013, 01:06 PM
Hello Chris,

Yes, please. You can open a support ticket and send us the demo project. 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Andie
Top achievements
Rank 1
answered on 30 Apr 2013, 05:39 PM
When you RaisePropertyChange on the ItemsSource it will always reset your SelectedValue. The way I get around this is by putting a flag in my setter for the SelectedValue in the ViewModel to not allow PropertyChange

_allowSelectedItemsPropertyChange = false;
RaisePropertyChagne(()=>  ItemSourceInViewModel )

_allowSelectedItemsPropertyChange = true;


   public object SelecedValueInViewModel
        {
            get
            {
                return _selectedValue
            }
            set
            {
                if (_allowSelectedItemsPropertyChange)
                {

                        selectedValue= value
                   }
                RaisePropertyChanged(() => SelecedValueInViewModel);

            }
        }

Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Chris
Top achievements
Rank 1
Andie
Top achievements
Rank 1
Share this question
or