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

Edit mode not cancelled when clicking on other controls

7 Answers 150 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lauren Nickerson
Top achievements
Rank 1
Lauren Nickerson asked on 29 Dec 2009, 11:27 PM
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.

7 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 30 Dec 2009, 08:21 AM
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.
0
Lauren Nickerson
Top achievements
Rank 1
answered on 30 Dec 2009, 07:26 PM
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.
0
Valentin.Stoychev
Telerik team
answered on 04 Jan 2010, 01:41 PM
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.
0
Lauren Nickerson
Top achievements
Rank 1
answered on 08 Jun 2010, 01:35 AM
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!
0
Valentin.Stoychev
Telerik team
answered on 10 Jun 2010, 05:51 PM
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.
0
Praveen
Top achievements
Rank 1
answered on 17 Feb 2016, 06:33 AM

Hey! Did you find any solutions to this issue?

 

0
Dinko | Tech Support Engineer
Telerik team
answered on 17 Feb 2016, 03:54 PM
Hi Praveen,

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

By default when the 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
Tags
TreeView
Asked by
Lauren Nickerson
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Lauren Nickerson
Top achievements
Rank 1
Praveen
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or