Editable sortable treeview

3 posts, 1 answers
  1. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 18 Jan 2014 Link to this post

    Hi,


    I implemented a sortable collection to use like itemssource for my RadTreeview. Each item is editable and when item is validated the sortable collection sort well the item. Normal behavior would be

    1 User start edit the item

    2 User enter Enter key

    3 Item is validated

    4 Item is sorted in sortablecollection and RadTreeView is updated. IsInEditMode is false.



    All works fine except if i decide to bind the IsInEditMode with a property of my model. When the IsInEditMode is binding (Mode TwoWay) the user must press twice Enter to complete the edit.



    I join a sample here.



    If you launch the sample and try to rename the 7ABC item in 0AAA, the item is well move to first position but stay in editmode. If you comment the following  line in MainWindow.xaml

    <Setter Property="IsInEditMode" Value="{Binding IsInEditMode,Mode=TwoWay}"/>
    the item is well move and exit from editmode when press Enter.



    I don't understand why the binding on IsInEditMode interfer with edition.



    Regards

    Luc

  2. Answer
    Boris
    Admin
    Boris avatar
    276 posts

    Posted 22 Jan 2014 Link to this post

    Hello luc,

    We found the cause of the issue and implemented a workaround for it. The issue was in the SortableCollection class:
    if (oldIndex != i)
                            {
                                this.MoveItem(oldIndex, i);
                            }
    where the MoveItem() method of the ObservableCollection raises a CollectionChanged event. This triggers refresh of the ItemsSource property of the RadTreeView and this prevents the proper ending of the edit mode. 
     
    The workaround for this issue is to set the IsInEditingMode to "false"  manually: 
    if (oldIndex != i)
                            {
                                this.MoveItem(oldIndex, i);
                                item.IsInEditMode = false;
                            }

    We have also attached the sample project with the suggested approach.

    I hope this information is helpful to you.

    Regards,
    Boris Penev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 22 Jan 2014 Link to this post

    Hi,

    Thanks it's work for this little project. More complicated with a generic SortableCollection<T> because IsInEditMode is not accessible.

    But i don't understand why when I comment the IsInEditMode bindings the behavior is different. In this case the CollectionChanged is raised too and the item exit from edition.

    Regards
Back to Top