TreeView - MouseDown at BeforeExpand

  • Thread starter Thread starter Jürgen Müllder
  • Start date Start date
J

Jürgen Müllder

Hi!

I have a TreeView in my Application. I have the MouseDown Attached to the
TreeView. When i click at a Node it makes that what it should. But when i
Expand a Node by clicking at the Plus Sign the MouseDown gets fired and it
runs the routine, what i don't want.

Is there a way to find out if the expand sign was clicked?

My Idea was to get a bool and a TreeNode in the class where i fetch the
BeforeExpand and set the bool to true and the TreeNode to the current one.
At the MouseDown i check if bool is false (otherwise BeforeExpand was
fired) and check if the selected Node != the TreeNode from the last Before
Expand (otherwise i clicked at another node, while bool is true). At the
end of MouseDown i set the bool back to false.

But this seems to be a little bit weird ;) There must be a easier way to do
this... someone have some suggestions, that would be great.


Greetings



Jürgen
 
Jurgen,

your problem is little confusing. I have a suggestion from what i have
understood

//declare a variable
private TreeNode previousTreeNode = null;

In the treeview_AfterSelect event

if(previousTreeNode != null)
{
if(treeview.SelectedNode == previousTreeNode )
return; //dont do anything becoz its same node
}
//store the selected node
previousTreeNode = treeview.SelectedNode;
//proceed with the logic

By doing this, you dont need to worry BeforeExpand and AfterExpand stuffs.
 
Back
Top