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
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

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".


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);
}
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
