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

how to disable leaving the edit mode

3 Answers 53 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
tomas
Top achievements
Rank 1
tomas asked on 06 Nov 2012, 09:25 PM
Hello Telerik,

MY treeview controlo is databound to colleciton of objects.

I would like to disable leaving the edit mode when some condition is fullfiled.

PreviewEdit
e.handled = true

is not working.

Do you have any tips?

When the edited item is losing focus and previewEdit handler is called but e.Handled = true does NOT working. The edit mode is terminated.

I have tried also this:

IsInEdit mode is databound to IsInEditMode property of RadTreeViewItem.

private void contextorTreeView_Edited(object sender, RadTreeViewItemEditedEventArgs e)
{
    VmContext tmpContext;
    if ((sender as RadTreeView).SelectedItem is VmContext)
    {
        tmpContext = (sender as RadTreeView).SelectedItem as VmContext;
        tmpContext.Validate();
        if (tmpContext.HasErrors)
        {
 
            tmpContext.IsInEditMode = true;
        }
    }
}
 
private void contextorTreeView_PreviewSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
     
    if (e.RemovedItems.Count > 0 && (e.RemovedItems[0] is VmContext) && (e.RemovedItems[0] as VmContext).IsInEditMode == true && (e.RemovedItems[0] as VmContext).Deleted  == false)
    {
        (e.RemovedItems[0] as VmContext).Validate();
        if ((e.RemovedItems[0] as VmContext).HasErrors)
        {
            e.Handled = true;
            (sender as RadTreeView).SelectedItem = e.RemovedItems[0];
        }
    }
}
The purpose of the first method is to disable terminating of the edit mode.

The purpose of the second method is to disable unselect the selected and edited item.

The problem is that the PreviewEdit is never fired again. Only for the first time. So when my validation is ok, there is constantly EditItemTemplate and not normal ItemTemplate. Also when I am editing another items there is no PreviewEdit event too.

IsInEditMode is databound using this style (twoWay binding):
<Style x:Key="contextContainerStyle" TargetType="telerik:RadTreeViewItem">
    <Setter Property="IsInEditMode" Value="{Binding IsInEditMode,Mode=TwoWay}" />
    <Setter Property="IsExpanded" Value="True" />
</Style>


Thanks Tom

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 08 Nov 2012, 05:00 PM
Hello Tom,

The approach with handling the preview event is the one that you need. However you have to handle the PreviewEdited event as this is the event that is fired before leaving the edit mode.

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

You can read more about the RadTreeView control in our help documentation.

All the best,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
tomas
Top achievements
Rank 1
answered on 08 Nov 2012, 05:06 PM
Hello PAvel,

I have already tried this, but it is not working. The event never fires.

Try this: Create edit template with forms containing some textboxes. Click inside the form but outside the textboxes. Edit mode is canceled and previewEdited never fires.

Thank you

Tom
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 09 Nov 2012, 12:23 PM
Hi Tom,

The PreviewEdited event is fired when you press the "Enter" key. If you press the "Esc" key or you click outside the TextBoxes of the edit form, you have to handle the PreviewEditCanceled event in order to keep the ItemEditTemplate active.

All the best,
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