• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

how to disable a node from tree to another tree using vb.net

hi. i want disable a node from a tree by selecting the same node on another tree
0
bensam
Asked:
bensam
1 Solution
 
anvCommented:
you need to traverse through the second tree till the selected node of first tree.
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.checkboxes.aspx
0
 
me655321Commented:
I don't know that you can officially 'disable' a treenode. If I understand you, you want to select the node in the first treeview and then not be able to select it in the second? Try this code.

Dim disabledNode As TreeNode
    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        'Set node as disabled
        disabledNode = TreeView2.Nodes.Find(e.Node.Name, True)(0)
        disabledNode.ForeColor = Color.Silver
    End Sub
    Private Sub TreeView1_BeforeSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeSelect
        If TreeView1.SelectedNode IsNot Nothing Then
            'Redraw node to regular color
            TreeView2.Nodes.Find(TreeView1.SelectedNode.Name, True)(0).ForeColor = Color.Black
        End If
    End Sub
    Private Sub TreeView2_BeforeSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView2.BeforeSelect
        If disabledNode IsNot Nothing AndAlso disabledNode Is e.Node Then
            'Cancel selection of node
            e.Cancel = True
        End If
    End Sub

Open in new window

0
 
bensamAuthor Commented:
thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now