How to handle double click on tree node?

6 posts, 1 answers
  1. paaland
    paaland avatar
    17 posts
    Member since:
    Jun 2009

    Posted 06 Oct 2011 Link to this post

    According to the documentation a double click on a tree node fires the following events (in order):
    • ItemClick event of the RadTreeView
    • DoubleClick event of the RadTreeViewItem
    • ItemDoubleClick event of the RadTreeView
    • Click event of the RadTreeViewItem
    • ItemClick event of the RadTreeView
    I want to do one thing on (single) click and another on double click. But since ItemClick runs also on double clicks this is difficult to manage.

    I attach the events as this

    this.myTree.ItemClick += new System.EventHandler<RadRoutedEventArgs>(myTree_ItemClick);
    this.myTree.ItemDoubleClick += new System.EventHandler<RadRoutedEventArgs>(myTree_ItemDoubleClick);

    If the events were called in the reverse order I could set the e.Handled = true, but alas. Any ideas?

    Using
       Silverlight 4 
       Telerik Silverlight controls 2011.2.920.1040

    Also why is the ItemClick event of the RadTreeView fired twice (according to document). That must be an error in the documentation.
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Oct 2011 Link to this post

    Hi Paal Andreassen,

    The sequence of events described in the documentation is accurate. The RadTreeView.ItemClick and RadTreeViewItem.Click events are fired twice on a double click. First they are fired when an item is clicked, then if a second click occurs in an interval indicating a double click, the RadTreeViewItem.DoubleClick and RadTreeView.ItemDoubleClick events are fired and lastly the RadTreeView.ItemClick and RadTreeViewItem.Click events are fired again to indicate the second single click. Basically since a double click means that a RadTreeViewItem is clicked twice, the single click events are raised twice.

    This is why in your case you'll have to use flags to implement your logic based on the type of click - single or double.

    If you can further elaborate on the requirements of your scenario, we will gladly assist you in implementing it.

    Regards,
    Tina Stancheva
    the Telerik team

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

  3. DevCraft banner
  4. paaland
    paaland avatar
    17 posts
    Member since:
    Jun 2009

    Posted 11 Oct 2011 Link to this post

    My requirements are simple. I want to call one method on single clicks and another method on double clicks :)

    The way I figure I need to solve this is to start a timer on the first ItemClick.
    If the timer times out then it's a single click.
    If another ItemClick on the same item is recevied before the timer times out then it's a double click.

    Doing this does not even require the ItemDoubleClick event.

    If you could provide a sample or even a better way of doing things I'd be happy.
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Oct 2011 Link to this post

    Hi Paal Andreassen,

    Using a timer is the best approach in your case. I attached a sample project that can help you get started. Let me know if I can further assist you.

    Regards,
    Tina Stancheva
    the Telerik team

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

  6. paaland
    paaland avatar
    17 posts
    Member since:
    Jun 2009

    Posted 12 Oct 2011 Link to this post

    Thank you, that worked fine. Since the treeview already have this kind of logic embedded (in order to support the OnDblclick event) it would be great if the event fireing was a bit more according to logic. I.e. a singleclick fires OnItemClick and a double click fires OnItemDoubleClick (if defined) or OnItemClick if not and nothing else.

  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 12 Oct 2011 Link to this post

    Hi Paal Andreassen,

    I am glad that the solution works for you. And I see your point on the matter and we will definitely take it into consideration. Thanks again for your feedback.

    Best wishes,
    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