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

How to handle TreeViewNode double click?

9 Answers 1334 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
cachuoi
Top achievements
Rank 1
cachuoi asked on 23 Sep 2009, 12:04 PM
Hi all,
I want to handle event doublclick of TreeViewNode but TreeView doesn't support. Please show me the way to do that.
Thanks in advance

9 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 24 Sep 2009, 11:32 AM
Hi cachuoi,

We don't have a double click event in the treeview, but if you want to expand/collapse the node on double click there is a property

IsExpandOnDblClickEnabled

which you can set to True.

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
cachuoi
Top achievements
Rank 1
answered on 27 Sep 2009, 05:16 PM
Hi Stoychev,
As you know, all TreeView control include RadTreeView default doubleclick to Expand/Collapse nodes which have child node. I need DoubleClick event on nodes which don't have childnode to do something. Ex: DoubleClick node to show Form Detail...
I need this event in GridView too. Could you help me?
Thanks
0
Kiril Stanoev
Telerik team
answered on 28 Sep 2009, 06:50 AM
Hello cachuoi,

Such functionality is not supported natively by RadTreeView therefore you need to handle the double-click even yourself. Here is an approach you might consider:
1. Attach a handler to your RadTreeView for the MouseLeftButtonDown event:

this.treeView1.AddHandler(RadTreeViewItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(treeView1_MouseLeftButtonDown), true); 

2. In the event handler you need to provide the logic for double-click detection.

// First get the selected item 
// Check whether the selected item has sub-items and if so,  
// check whether the doubleClickFlag has been raised -> display MessageBox 
// else start the doubleClickTimer and raise the flag 
void treeView1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    RadTreeViewItem selectedItem = treeView1.SelectedItem as RadTreeViewItem; 
    if (selectedItem != null && selectedItem.Items.Count == 0) 
    { 
        if (this.doubleClickFlag) 
        { 
            MessageBox.Show("Wow"); 
        } 
        else 
        { 
            this.doubleClickTimer.Start(); 
            this.doubleClickFlag = true
        } 
    } 

I am attaching my sample project for further reference. Give it a try and let me know whether this serves your purposes.

Regards,
Kiril Stanoev
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
cachuoi
Top achievements
Rank 1
answered on 28 Sep 2009, 07:05 AM
Hi Stanoev,
Thanks for your help. Your sample have resolved my problem. But I see that, I have about 10 or more RadTreeViews, so I have to implement 10 or more MouseLeftButtondown and Timer?
I wonder you can handle DoubleClick to Expand/Collapse Node so why can't raise event DoubleClick if check this node doesn't have any childnode?
If next release have this feature (GridView also), We will be very happy :)
Thanks in advance
0
Accepted
Kiril Stanoev
Telerik team
answered on 28 Sep 2009, 08:27 AM
Hello cachuoi,

Thank you for your feature suggestion. If there is enough demand, we will definitely consider it for our future versions of RadTreeView and RadGridView.
Back to your initial question. You do not need to implement 10 timers if you have 10 RadTreeViews. All you have to do is to attach MouseLeftButtonDown event handlers on each RadTreeView...

this.treeView1.AddHandler(RadTreeViewItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(treeView1_MouseLeftButtonDown), true); 
this.treeView2.AddHandler(RadTreeViewItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(treeView1_MouseLeftButtonDown), true); 
this.treeView3.AddHandler(RadTreeViewItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(treeView1_MouseLeftButtonDown), true); 

...and slightly change the logic in the MouseLeftButtonDown event handler, so that it knows which is the sender treeview:

void treeView1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
             
    RadTreeView senderTreeView = sender as RadTreeView; 
    if(sender == null
    { 
        return
    } 
 
    RadTreeViewItem selectedItem = senderTreeView.SelectedItem as RadTreeViewItem; 
    if (selectedItem != null && selectedItem.Items.Count == 0) 
    { 
        if (this.doubleClickFlag) 
        { 
            MessageBox.Show("Wow"); 
        } 
        else 
        { 
            this.doubleClickTimer.Start(); 
            this.doubleClickFlag = true
        } 
    } 

I am attaching my test project again, as a demonstration. Let me know if you experience further problems.


Best wishes,
Kiril Stanoev
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
Daniel
Top achievements
Rank 1
answered on 07 Feb 2010, 03:20 PM
I am definitely interested.
0
Valentin.Stoychev
Telerik team
answered on 08 Feb 2010, 08:51 AM
Hello Daniel,

You can Vote and to track the status of this feature request in our new public issue tracking system (PITS) here:
http://www.telerik.com/support/pits.aspx#/public/silverlight/486

Kind regards,
Valentin.Stoychev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Francis Frank
Top achievements
Rank 1
answered on 29 Nov 2011, 10:50 AM
Please in which part of my aspx.cs should i add this handler?

I want to get the child node which ,doesnt have any childnode on it

Thanks
0
Tina Stancheva
Telerik team
answered on 02 Dec 2011, 09:26 AM
Hello Francis Frank,

In this forum thread is discussed how to handle a double click event for the RadTreeView control for Silverlight.

However, from your question it seems that you're interested in the RadTreeView control for ASP.NET AJAX. If this is the case, you can take a look at this article as it describes all methods and properties of the TreeNodes. Basically in order to get a node which have no children, you can use the get_nodes() method and check the count of the children with get_count(). You can also examine this article listing the programming tasks that can be performed on the server.

Let us know if you need more information. Also, please keep in mind, that when you have issues with a control, it is best to start a thread and indicate the RadControl type and suite. This will ensure that your questions will reach the respective developers, if needed.

For anyone else following this thread, I just wanted to let you know that the RadTreeView and RadTreeViewItem controls for Silverlight now expose a Click and DoubleClick events. You can find more information here.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeView
Asked by
cachuoi
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
cachuoi
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Daniel
Top achievements
Rank 1
Francis Frank
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or