how to disable leaving the edit mode

4 posts, 1 answers
  1. tomas
    tomas avatar
    139 posts
    Member since:
    Sep 2012

    Posted 06 Nov 2012 Link to this post

    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
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 08 Nov 2012 Link to this post

    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.

  3. DevCraft banner
  4. tomas
    tomas avatar
    139 posts
    Member since:
    Sep 2012

    Posted 08 Nov 2012 Link to this post

    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
  5. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 09 Nov 2012 Link to this post

    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.

Back to Top