I am working on a winform and on my UI there is a treeview, I found that the treenode will be highlighted even I did not click on the node by right mouse (eg, Node1 will be high
I have found another method to prevent the node to be highlight when the user not click on the node, and I only set the BackColor and ForeColor for each of the node when adding it to the tree
newNode.BackColor = treeview1.BackColor;
newNode.ForeColor = treeview1.ForeColor;
treeview1.Nodes.Add(newNode);
Then in the MouseDown event, set the SelectedNode property as following
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
TreeNode Node = treeView1.GetNodeAt(e.Location);
if (Node != null && Node.Bounds.Contains(e.Location))
treeView1.SelectedNode = Node;
else
treeView1.SelectedNode = null;
}