How to handle TreeViewNode double click?

10 posts, 1 answers
  1. cachuoi
    cachuoi avatar
    6 posts
    Member since:
    Jun 2006

    Posted 23 Sep 2009 Link to this post

    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
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 24 Sep 2009 Link to this post

    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.
  3. DevCraft banner
  4. cachuoi
    cachuoi avatar
    6 posts
    Member since:
    Jun 2006

    Posted 27 Sep 2009 Link to this post

    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
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 28 Sep 2009 Link to this post

    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.
  6. cachuoi
    cachuoi avatar
    6 posts
    Member since:
    Jun 2006

    Posted 28 Sep 2009 Link to this post

    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
  7. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 28 Sep 2009 Link to this post

    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.
  8. Daniel
    Daniel avatar
    11 posts
    Member since:
    May 2009

    Posted 07 Feb 2010 Link to this post

    I am definitely interested.
  9. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 08 Feb 2010 Link to this post

    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.
  10. Francis Frank
    Francis Frank avatar
    35 posts
    Member since:
    Mar 2010

    Posted 29 Nov 2011 Link to this post

    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
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 02 Dec 2011 Link to this post

    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 >>

Back to Top
DevCraft banner