Edit mode not cancelled when clicking on other controls

8 posts, 0 answers
  1. Lauren Nickerson
    Lauren Nickerson avatar
    52 posts
    Member since:
    Jul 2009

    Posted 29 Dec 2009 Link to this post

    Hi. The problem is that when a tree item goes in edit mode and you click on another tree item, the edit mode goes away. But when you do so with any other control (E. G. a button), it stays. We want it to go away too, how can we achieve that?

    Here's what I'm talking about.

    Thanks.
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 30 Dec 2009 Link to this post

    Hello Lauren Nickerson,

    You can cancel the edit mode by using the IsInEditMode property of the item. You can handle the LostFocus event of the RadTreeView and to execute the code in the event handler.

    Please let us know if more info is needed.

    Best wishes,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lauren Nickerson
    Lauren Nickerson avatar
    52 posts
    Member since:
    Jul 2009

    Posted 30 Dec 2009 Link to this post

    Yes, I have another question. I used this code:

            private void treeViewExperimentExplorer_LostFocus(object sender, RoutedEventArgs e) 
            { 
                RadTreeViewItem selectedItem = (sender as RadTreeView).SelectedContainer as RadTreeViewItem; 
     
                if (selectedItem.IsInEditMode) 
                    selectedItem.CancelEdit(); 
            } 

    But apparently, the LostFocus event happens when I hit F2 to enter edit mode, so it gets cancelled right away. What's a good way to accomplish this without the Edit getting cancelled when F2 is entered?

    Thanks.
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 04 Jan 2010 Link to this post

    Hi Lauren Nickerson,

    You can use this code.

    private void RadTreeView_LostFocus(object sender, RoutedEventArgs e)
    {
        object focusedElement = FocusManager.GetFocusedElement();
        RadTreeView treeView = (focusedElement as FrameworkElement).ParentOfType<RadTreeView>();
        if (treeView != null && treeView.Equals(sender))
        {
            return;
        }
        (sender as RadTreeView).SelectedContainer.IsInEditMode = false;
    }

    Greetings,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Lauren Nickerson
    Lauren Nickerson avatar
    52 posts
    Member since:
    Jul 2009

    Posted 07 Jun 2010 Link to this post

    Hi, thanks for the suggestion, but the code didn't work. It gets called as soon as I press F2, so at the exact same time editing  begins, LostFocus event happens, and cancels the edit. Any other solution?

    Thanks!
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 10 Jun 2010 Link to this post

    Hello Lauren Nickerson,

    Can you give us some more details on your setup. Do you reproduce the problem when run the treeview in an isolated setup?

    Kind regards,
    Valentin.Stoychev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Praveen
    Praveen avatar
    5 posts
    Member since:
    Apr 2015

    Posted 17 Feb in reply to Lauren Nickerson Link to this post

    Hey! Did you find any solutions to this issue?

     

  9. Dinko
    Admin
    Dinko avatar
    204 posts

    Posted 17 Feb Link to this post

    Hi Praveen,

    We already answered your question in your support thread. We are copying the answer also here:

    By default when the treeview item lost the focus while in edit mode, the edit mode will be canceled. In order to achieve the same effect for non-focusable controls which cannot get the focus from the items, you can implement custom behavior in the MouseLeftButtonDown event of the main view (the main window for example). Basically, you can check if the mouse is under the edit element and if not exit the edit mode.
    public MainWindow()
    {
        InitializeComponent();
      this.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new      MouseButtonEventHandler(MainWindow_MouseLeftButtonDown),true);
    }
      
    void MainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        var clickedItem = e.OriginalSource as FrameworkElement;
        var treeViewItem = clickedItem.ParentOfType<RadTreeViewItem>();
        if (treeViewItem != null)
        {
            var editElement = treeViewItem.ChildrenOfType<ContentPresenter>().FirstOrDefault(x => x.Name == "EditHeaderElement");
            if (editElement != null || editElement.Visibility != Visibility.Collapsed)
            {
                return;
            }
        }
                      
        var selectedItem = this.tree.SelectedItem as RadTreeViewItem;
        if (selectedItem != null)
        {
            selectedItem.CancelEdit();
            selectedItem.IsInEditMode = false;
        
    }

    Regards,
    Dinko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready