Results 1 to 4 of 4

Thread: How to Highlight TreeView.SelectedNode in VB.Net

  1. #1
    Join Date
    Feb 2009
    Posts
    81

    How to Highlight TreeView.SelectedNode in VB.Net

    How do I highlight a selected node programatically?

    After I click a Menu Item, some default settings get automatically selected for the node. When this event occurs the selected node performs correctly but the selected node not get highlighted. How do I highlight it?

    Following is the sample code:


    Code:
    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MenuItem1.Click
    
    TreeView1.SelectedNode = TreeView1.Nodes(0).Nodes(5)
    
    End Sub
    Thanks for your help.

  2. #2
    Join Date
    Oct 2008
    Posts
    167

    Re: How to Highlight TreeView.SelectedNode in VB.Net

    Use the DragOver event to determine what you are dragging over - (as you
    should anyway to determine whether its ok to do so) and then set the current
    item as the selected item (something like this - )

    Private Sub TreeView_DragOver(ByVal sender As Object, ByVal e As
    System.Windows.Forms.DragEventArgs) Handles TreeView.DragOver
    Assume we can't drop

    Dim mousePos As Point
    mousePos = TreeView.PointToClient(Cursor.Position)

    Dim nodeOver As MultiSelectTreeViewNode =
    CType(TreeView.GetNodeAt(mousePos), MultiSelectTreeViewNode)

    If nodeOver Is Nothing Then
    Exit Sub
    Else
    TreeView.SelectedNode = nodeOver
    end if
    end sub

  3. #3
    Join Date
    Apr 2008
    Posts
    193

    Re: How to Highlight TreeView.SelectedNode in VB.Net

    You may also try using the following code where Controls are not highlighted until selected unless HideSelection = False

    Code:
    Me.tvVirtualItems.BeginUpdate()
                Me.tvVirtualItems.SelectedNode = PointedNode
                Me.tvVirtualItems.Select()
                Me.tvVirtualItems.EndUpdate()

  4. #4
    Join Date
    Dec 2008
    Posts
    202

    Re: How to Highlight TreeView.SelectedNode in VB.Net

    while finding an solution to your problem i finally got the solution...
    i need to check each Main node Child Node and Grand Child node
    Here is the code:

    Code:
    If Not MySelectedNode Is Nothing Then
                    For Each RootNode As TreeNode In TreeView.Nodes
                        If RootNode.Text = MySelectedNode.Text Then TreeView.SelectedNode = RootNode
                        For Each ChildNode As TreeNode In RootNode.Nodes
                            If ChildNode.Text = MySelectedNode.Text Then TreeView.SelectedNode = ChildNode
                            For Each GrandChildNode As TreeNode In ChildNode.Nodes
                                If GrandChildNode.Text = MySelectedNode.Text Then TreeView.SelectedNode = GrandChildNode
                            Next
                        Next
                    Next
                End If
    now working good

Similar Threads

  1. Treeview in VBA in Excel
    By The-Farmer in forum MS Office Support
    Replies: 1
    Last Post: 28-01-2012, 03:48 PM
  2. Silverlight Treeview examples in VB
    By Sheravat in forum Software Development
    Replies: 5
    Last Post: 06-08-2010, 05:38 AM
  3. How to add an Image to a parent node in a treeview?
    By Casie in forum Software Development
    Replies: 4
    Last Post: 27-01-2010, 05:02 PM
  4. Features of Flexible TreeView
    By michaels in forum Windows Software
    Replies: 5
    Last Post: 22-01-2010, 05:32 AM
  5. Treeview with wpf module as child
    By Wyvern in forum Software Development
    Replies: 5
    Last Post: 11-12-2009, 05:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,832,976.70180 seconds with 17 queries