how to disable a node from tree to another tree using

Posted on 2009-12-17
Last Modified: 2012-05-08
hi. i want disable a node from a tree by selecting the same node on another tree
Question by:bensam
    LVL 10

    Expert Comment

    you need to traverse through the second tree till the selected node of first tree.
    LVL 4

    Accepted Solution

    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


    Author Closing Comment

    thank you

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now