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

MVVM RowEditEnded - SelectedItem when sorted/filtered

2 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 06 Sep 2012, 06:13 PM
I need a little help...

I have an editable RadGrid. I invoke a command when the user finishes editing a row.  The command saves the edited item.  I have accomplished this using the Interactivity assembly, and add an event trigger on the RowEditEnded event.  The InvokeCommandAction invokes a command and passes the SelectedItem as the commandparameter.  The viewmodel then saves the parameter object. (the edited item)
<i:Interaction.Triggers>
  <i:EventTrigger EventName="RowEditEnded">
    <i:InvokeCommandAction
      Command="{Binding SaveSelectedProjectCommand}"
      CommandParameter="{Binding ElementName=grdProjects, Path=SelectedItem}" />
   </i:EventTrigger>
</i:Interaction.Triggers>

This works as expected. 
However, when the grid is sorted or filtered, under certain circumstances the command parameter (the SelectedItem) is NULL.
Specifically, if the change the user makes causes the edited row to be moved or removed in the grid.
Ex.  If the Grid is sorted on Column A, and the user edits a value in Column A that causes it to be moved up or down.  The Command is fired, but the parameter (SelectedItem) is NULL.

Thoughts on how I could solve this? 

Thanks,
Justin

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 07 Sep 2012, 01:17 PM
Hi,

 May I ask you could set the IsSyncronizedWithCurrentItem property of the GridView to True? That way the SelectedItem will be always the CurrentItem. I hope this helps.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Justin Lee
Top achievements
Rank 1
answered on 07 Sep 2012, 01:39 PM
I tried your suggestion and set IsSyncronizedWithCurrentItem to true.  The parameter passed to the command (SelectedItem) is now never null, however it is NOT the correct item when the grid is sorted/filtered. (not the item that was just edited).  It passes the item whose current index is the index of the edited item BEFORE the change was made.

Example: 
There are 3 items in the grid that are sorted.  
    Item X
    Item Y
    Item Z
User changes the name of Item Y to be "Item A", the grid re-sorts to: 
    Item A
    Item X
    Item Z
At this point, the command is passed Item X, when it should be saving Item A. 

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