?
Solved

Could not Set TreeView.SelectedNode

Posted on 2007-12-04
5
Medium Priority
?
1,699 Views
Last Modified: 2012-05-05
Hi
I am creating windows application using VB.NET 2005
and i have a TreeView on my form.
after select a node and do some operation
then i am repapulating TreeView
then i want to Highlight Node which user was clicked or selected.

i am saving user last selected node in a Node
here i smy code
  Private MySeletedNode As TreeNode
Private Sub TreeView_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView.AfterSelect
 MySeletedNode = TreeView.SelectedNode
End Sub

Private sub LoadData()
 TreeView.Nodes.Clear()
--Adding Nodes here
'here setting Slected node is LastSelectedNode
 TreeView.SelectedNode = MySeletedNode
End Sub

but TreeView.SelectedNode  is showing Nothing
is any wrong in my code?
0
Comment
Question by:RamanaChoudary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20408473
you cannot do that, you cannot "save" the selection, clear and repopulate.
But you can do this:
give each tree node some kind of key or ID, a number, a name. Store it in the TreeViewNode.Tag member.
Clear your control and repopulate.
WHILE repopulating, compare the ID of the nodes with the saved ID, if you find a match, set to SelectedNode to that node.
0
 
LVL 4

Author Comment

by:RamanaChoudary
ID: 20412200
ya thats what i am doing there..
but no luck..
  ''here Expanding the perticular node which was user selected.
            If Not MySeletedNode Is Nothing Then
                TreeView.SelectedNode = MySeletedNode
                For Each RootNode As TreeNode In TreeView.Nodes
                    For Each ChildNode As TreeNode In RootNode.Nodes
                        If ChildNode.Text = MySeletedNode.Parent.Text Then
                            TreeView.SelectedNode = MySeletedNode
                            TreeView.Focus()
                        End If
                    Next
                Next
            End If
0
 
LVL 4

Accepted Solution

by:
RamanaChoudary earned 0 total points
ID: 20413111
Never Mind i got the solution...
i need to check each Main node Chaild Node and Grand Child node
here is the 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
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20465364
Closed, 100 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 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