MVVM RowEditEnded - SelectedItem when sorted/filtered

3 posts, 0 answers
  1. Justin Lee
    Justin Lee avatar
    170 posts
    Member since:
    Dec 2009

    Posted 06 Sep 2012 Link to this post

    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. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Sep 2012 Link to this post

    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.

  3. Justin Lee
    Justin Lee avatar
    170 posts
    Member since:
    Dec 2009

    Posted 07 Sep 2012 Link to this post

    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
Back to Top