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

Cannot Enter Edit Mode on Left Mouse Click

2 Answers 34 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
PMoransais
Top achievements
Rank 1
PMoransais asked on 23 Feb 2012, 07:58 PM
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                 
                _TV.SelectedContainer.BeginEdit()
                ' 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.

Thanks

           


2 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 27 Feb 2012, 04:11 PM
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)
    {
        return;
    }
 
    if (this.lastContainer == null)
    {
        this.lastContainer = currentContainer;
    }
    else if (this.lastContainer.Equals(currentContainer))
    {
        currentContainer.IsInEditMode = true;
        this.lastContainer = null;
    }
    else
    {
        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.

Regards,
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 >>
0
PMoransais
Top achievements
Rank 1
answered on 05 Mar 2012, 03:21 PM
Thanks Kiril,

It works perfectly!

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

Philippe
Tags
TreeListView
Asked by
PMoransais
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
PMoransais
Top achievements
Rank 1
Share this question
or