Edit node name after adding new node

7 posts, 1 answers
  1. rico
    rico avatar
    15 posts
    Member since:
    Aug 2017

    Posted 10 Aug Link to this post

    I have a RadTreeView with an underlying Collection. When I add a new item to that collection I want to set that node into edit mode so the user can immediately enter a name for that node.

    After modifying the collection and calling Refresh() on it I call BeginEdit() on the newly created RadTreeViewItem. The item is not set into edit mode though. When I call BeginEdit() on another node, that node is set into edit mode. It seems to be only the newly created item which does not enter the desired state.

  2. Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 14 Aug Link to this post

    Hello rico,

    Thank you for your interest in RadTreeView control.

    To start the editing process you can set the IsInEditMode property of the RadTreeViewItem to true. How can you do this? You can create bool property in your model IsInEditModeProperty. Then in a custom style with target type set to RadTreeViewItem you can bind the IsInEditMode to the from the model. To apply the custom style you can set it to the ItemContainerStyle property of the RadTreeView. Keep in mind that in order to apply the changes you can set custom data template to the ItemEditTemplate property. The IsInEditMode property is designed to open/close the editing mode only. In addition, you can take a look at the How to Edit An Item help article in our documentation.

    I have created sample project which demonstrates this approach. In the attached project you can see that when the button is pressed an item is added to the tree in edit mode.

    Regards,
    Dinko
    Progress Telerik
    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.
  3. rico
    rico avatar
    15 posts
    Member since:
    Aug 2017

    Posted 16 Aug in reply to Dinko Link to this post

    Thank you for your response.

     

    When I start your test project I see only a white window - no button to click. But looking at the code I could copy the behavior into my project. What happens now is: The node goes into edit mode but the name of the node is not shown (when a new node is created it gets a default name "New Node"). I see an empty entry field. When I enter something and press enter, the corresponding change events are called but the value of the new name is still "New Node".

  4. rico
    rico avatar
    15 posts
    Member since:
    Aug 2017

    Posted 16 Aug in reply to rico Link to this post

    I just figured out what the problem was. I didn't specify an ItemEditTemplate. Now it seems to work. Is it possible to auto-mark the node name when setting it into edit mode? Now the cursor is at the beginning of the textbox and the user has to delete the current value first.
  5. rico
    rico avatar
    15 posts
    Member since:
    Aug 2017

    Posted 18 Aug in reply to rico Link to this post

    I figured out that simply setting the IsInEditMode property to true does actually work if it is done in the Dispatcher thread or with a System.Threading.Timer with a delay of 1ms. I don't know what happens in the tree but obviously it takes a short time or probably rather a thread change for the tree to refresh. Is there a cleaner solution for this?
  6. Answer
    Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 18 Aug Link to this post

    Hi rico,

    I have double check the attached project and it is working as expected. You can double check if you have reference NoXAML DLLs. If you are using NoXAML binaries you need to merged the required dictionaries. You can take a look at the Styling the Controls help article in our documentation.

    For selecting all the text when you add a node you can subscribe the GotFocus event of the TextBox in the ItemEditTemplate. In the event handler you can call the SelectAll() method in a Dispatcher.
    private void TextBox_GotFocus(object sender, RoutedEventArgs e)
    {
        var txtBox = sender as TextBox;
        Dispatcher.BeginInvoke((Action)(()=> {
            txtBox.SelectAll();
        }),DispatcherPriority.DataBind);
    }
    You can take a look at the attached project which demonstrates this approach.

    As for your last question, I am not exactly sure how you have implemented the approach in your scenario. At this point, I can't give you better approach from the one explained in your post.

    Regards,
    Dinko
    Progress Telerik
    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.
  7. rico
    rico avatar
    15 posts
    Member since:
    Aug 2017

    Posted 18 Aug in reply to Dinko Link to this post

    Thank you very much.
Back to Top