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

focus

3 Answers 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
tomas
Top achievements
Rank 1
tomas asked on 08 Nov 2012, 02:10 PM
hi telerik,

How  can I disable an item to lose focus?

When I am editing the item and there are some validation errors, I dont want to terminate the edit mode.

My treeview is databound to collection of objects. Objects have required properties. Item editing is visualized using a form with a several textboxes.

Thank you.

Tom

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 09 Nov 2012, 12:22 PM
Hi Tom,

In order to keep the editing mode of an RadTreeViewItem you have to handle the PreviewEditCanceled and the PreviewEdited events. The first one is fired when the form containing the TextBoxes looses focus and the second one is fired when the "Enter" key is pressed. You can use the following snippets:

XAML:
<telerik:RadTreeView IsEditable="True"
               PreviewEdited="RadTreeView_PreviewEdited"
               PreviewEditCanceled="RadTreeView_PreviewEditCanceled"
               ItemEditTemplate="{StaticResource EditTemplate}">
      <telerik:RadTreeViewItem Header="root">
        <telerik:RadTreeViewItem Header="item1" />
        <telerik:RadTreeViewItem Header="item2" />
      </telerik:RadTreeViewItem>
    </telerik:RadTreeView>

C# :
private void RadTreeView_PreviewEdited(object sender, Telerik.Windows.Controls.RadTreeViewItemEditedEventArgs e)
{
  e.Handled = true;
}
 
private void RadTreeView_PreviewEditCanceled(object sender, RadTreeViewItemEditedEventArgs e)
{
  e.Handled = true;
}


Regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
tomas
Top achievements
Rank 1
answered on 09 Nov 2012, 02:12 PM
Thank you very much.

It is working now. Enter and Escape keys do nothing for me. Actulally, Enter collapse and expand node. But they do nothing with a state of edit mode.

Anyway previewEditCanceled is raised when I click somewhere in the form but outside the controls in a form thus this is working form me and I am satisfied. Thank you.

But there is stil one problem:

Imagine this situation. You need to use different dataedittemplates based on value of one properties of an object in a hierarchy.

For example when a property value is equal 1 than you will have 2 textboxes. When the value is 2 you will have 4 textboxes.

I am trying to use itemEditTemplateSelector, but the selected template is not changing. (There must be some caching)  The selector code is called only for the first time. I am trying also to create one big form containing all textboxes and to bind their visibility to item itself to inspect their properties using a converter. But again, converter is called only for the firsttime. Do you know, how to solve this?

The first time = when I am editing for the first time.

I have a toolbar when a user can add aspects of the selected node. When you add aspects => you should see more controls in a edit form.

Thank you very much.

Tom


0
Pavel R. Pavlov
Telerik team
answered on 14 Nov 2012, 02:16 PM
Hello Tom,

The ItemEditTemplateSelector is called only once before the RadTreeViewItems are visualized after that the template is cashed in memory and loaded from there for better performance. In order to change the ItemEditTemplate dynamically you have to do it on events triggering in code behind. You can try to listen when the user will clicks the F2 key and then load the desired ItemEditTemplate (based on your custom logic). Keep in mind that you have to change the HeaderEditTemplate of the selected RadTreeViewItem.

When the F2 key is pressed the RadTreeView will reload the template and then will continue with the editing logic. So if you load a different template just before the old one is applied you will achieve your goal. Please note that this approach is considered as very bad practice and unexpected behavior may occur.

Kind regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeView
Asked by
tomas
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
tomas
Top achievements
Rank 1
Share this question
or