Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2009
Member
 
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.
Reply With Quote
  #2  
Old 03-03-2009
Member
 
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

Quote:
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
Reply With Quote
  #3  
Old 03-03-2009
Member
 
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()
Reply With Quote
  #4  
Old 03-03-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 12:52 AM.