Limit left click event on treeview?

ThienZ

Freshman
Joined
Feb 10, 2005
Messages
45
Location
Germany
i made a treeview and want to check or uncheck the node if mouse is clicked over it.

my code looks like this :

Code:
private void treeViewBildObjekt_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
	TreeNodeExt selectedNode = (TreeNodeExt) treeViewBildObjekt.GetNodeAt(
		treeViewBildObjekt.PointToClient(Cursor.Position));

	if ((selectedNode != null) && (e.Button == MouseButtons.Left)) 
	{
		selectedNode.Checked = !selectedNode.Checked;
	}
}

but if i click on the same height as the node, not on the text, the node would be checked or unchecked too... this would be inconvenient for the users, because the width of the treeview is big, so if the user click on the empty space on the right or left side of the tree, the node on the same height is going to be checked or unchecked..

how can i make so this would only happen if i click on the text?

thx in advance :)

ps: i'm using C# if it makes any differences
 
You might try the Bounds property of the node and check if the mouse is within the Bounds rectangle. I think (havent checked though so don't get angry if I'm wrong ;) ) it is the area that gets the focus rectangle when selecting a treenode.
 
Back
Top