1
votes

I have 2 TreeView controls and the user selects one of the nodes in TreeView1 and then selects one node in TreeView2.
The problem is that when he selects the other TreeView's node, the previous one leaves the focus so that the user wont know which TreeView was selected.

Is there any way to keep focus on 2 TreeNodes or change the ForeColor/ make the selected node bold so that the selected node will still be visible.

2
Do you mean by clicking on a node in one of treeviews, some other node get selected in other treeview?!Saeid Yazdani

2 Answers

3
votes

Set the TreeView's HideSelection property to false:

Gets or sets a value indicating whether the selected tree node remains highlighted even when the tree view has lost the focus.

1
votes

You can have 2 fields to keep track of selected nodes of both treeview you have (Using AfterSelect event). Something like:

    private TreeNode selectedNodeA;
    private TreeNode selectedNodeB;

    private void treeViewA_AfterSelect(object sender, TreeViewEventArgs e)
    {
        //Reset color if was perviously highlighted
        if (selectedNodeA != null)
            selectedNodeA.BackColor = Color.White;

        selectedNodeA = e.Node;

        //Here you can indicate the node is selected, change background color or set font to
        // Bold or any other tricks!
        selectedNodeA.BackColor = Color.LightGray;

         //Rest of code
     }

Above code is for the time you need different color than the default color winforms uses (By setting HideSelection to false as Stuart said.