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

Edit node name after adding new node

6 Answers 226 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
rico
Top achievements
Rank 1
rico asked on 10 Aug 2017, 06:47 AM

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.

6 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Aug 2017, 01:36 PM
Hello ,

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 you to write beautiful native mobile apps using a single shared C# codebase.
0
rico
Top achievements
Rank 1
answered on 16 Aug 2017, 10:33 AM
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".

0
rico
Top achievements
Rank 1
answered on 16 Aug 2017, 03:19 PM
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.
0
rico
Top achievements
Rank 1
answered on 18 Aug 2017, 12:19 PM
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?
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 18 Aug 2017, 01:09 PM
Hi ,

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.
0
rico
Top achievements
Rank 1
answered on 18 Aug 2017, 01:17 PM
Thank you very much.
Tags
TreeView
Asked by
rico
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
rico
Top achievements
Rank 1
Share this question
or