Cannot Enter Edit Mode on Left Mouse Click

3 posts, 0 answers
  1. PMoransais
    PMoransais avatar
    17 posts
    Member since:
    Mar 2007

    Posted 23 Feb 2012 Link to this post

    I am trying to emulate Windows general behavior for editing treeview nodes: clicking on an already selected node enters the editing mode.

    With RadTreeView (WPF) I can handle the previewMouseDown events, as well as the left and right mouse button preview events of the treeview.
                AddHandler _TV.PreviewMouseDown, AddressOf tv_PreviewMouseDown 

    In the event handler i call  begin edit (TV.SelectedContainer.BeginEdit() or myradTreeviewitem.BeginEdit).
            Private Sub tv_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) 
                Dim s = TryCast(e.OriginalSource, UIElement)             
                If s Is Nothing Then Exit Sub             
                    Dim Item = UI.Library.FindVisualParent(Of Telerik.Windows.Controls.RadTreeViewItem)(s)
                   If Item Is Nothing Then Exit Sub             
                    If Item.IsSelected Then                 
                    ' Item.BeginEdit
                End If         
            End Sub

    UI.Library.FindVisualParent is a small function that returns the parent of Type T of an element
    This code works perfectly with a Righ Mouse click.
    It does not work with a Left Mouse Click
    In other words, BeginEdit does not work when called on a previewMouseDown if the left button triggered the event.

    The PreviewMouseRightButtonDown  works using the same handler.
    The PreviewMouseLeftButtonDown works using the same handler.

    Is there a reason why this is so. It is important for my application that I can keep windows interface conventions like clicking on the selected Tree Node enters editing mode.

    Any help will be appreciated.



  2. Kiril Stanoev
    Kiril Stanoev avatar
    1512 posts

    Posted 27 Feb 2012 Link to this post

    Hi Philippe,

    For this particular scenario you can use the ItemClick event of RadTreeView.

    <telerik:RadTreeView x:Name="treeView1" Style="{StaticResource RadTreeViewStyle}"
            ItemContainerStyle="{StaticResource RadTreeViewItemStyle}" ItemClick="TreeView_ItemClick" />

    private RadTreeViewItem lastContainer;
    private void TreeView_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
        RadTreeViewItem currentContainer = e.OriginalSource as RadTreeViewItem;
        if (currentContainer == null)
        if (this.lastContainer == null)
            this.lastContainer = currentContainer;
        else if (this.lastContainer.Equals(currentContainer))
            currentContainer.IsInEditMode = true;
            this.lastContainer = null;
            this.lastContainer = null;

    All you have to do now is implement some DispatcherTimer which will rename the node only if 500 milliseconds have not passed yet.

    Give it a try and let me know how it goes.

    Kiril Stanoev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. PMoransais
    PMoransais avatar
    17 posts
    Member since:
    Mar 2007

    Posted 05 Mar 2012 Link to this post

    Thanks Kiril,

    It works perfectly!

    (Sorry for the late answer, I was off last week)

Back to Top