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

How to handle double click on tree node?

5 Answers 672 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
paaland
Top achievements
Rank 2
paaland asked on 06 Oct 2011, 01:57 PM
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.

5 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 11 Oct 2011, 12:50 PM
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 >>

0
paaland
Top achievements
Rank 2
answered on 11 Oct 2011, 12:54 PM
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.
0
Accepted
Tina Stancheva
Telerik team
answered on 11 Oct 2011, 02:43 PM
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 >>

0
paaland
Top achievements
Rank 2
answered on 12 Oct 2011, 07:56 AM
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.

0
Tina Stancheva
Telerik team
answered on 12 Oct 2011, 08:10 AM
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 >>

Tags
TreeView
Asked by
paaland
Top achievements
Rank 2
Answers by
Tina Stancheva
Telerik team
paaland
Top achievements
Rank 2
Share this question
or