Click here to Skip to main content
15,888,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have a problem on Double click of tree view. I want to avoid double click of tree view when double click on +/- of tree view. please anyone tell me, How to avoid this?


thanks in advance.
Posted
Updated 9-Aug-23 16:37pm

You cannot avoid double click: the user clicks as many time as she/he wants. :-)

—SA
 
Share this answer
 
You cannot doubleclick on the +/- of the treenodes. The nodes expand and collapse on a single click. I tried suppressing the doubleclick but as SAKryukov says, its not possible to do that. Its because the event BeforeExpand gets handled before the event MouseDoubleClick, otherwise we could have cancelled the expansion of nodes by setting the e.Cancel = true in the BeforeExpand event.
Here is how I tried:

C#
private bool isDoubleClick = false;

void treeView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
 isDoubleClick = true;
}

//But this event is called before MouseDoubleClick so isDoubleClick will be false.
void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
 if (isDoubleClick == true)
  {
   e.Cancel = true;
  }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900