highlight treeview node

i want to find treeview node and highlight with some color, please tell me the solution.  
Who is Participating?
Wayne Taylor (webtubbs)Connect With a Mentor Commented:
Use the below code to highlight the node *named* "Node12".

        Dim nds() As TreeNode = TreeView1.Nodes.Find("Node12", True)
        If nds.Length > 0 Then
            nds(0).BackColor = Color.Red
        End If

Open in new window

Éric MoreauSenior .Net ConsultantCommented:
farjack1Author Commented:
i tried this code but its not working i have tried to pass NodeID or  NodeName but still not working b/c  
nds.Length always comming 0 i dont know way

  Dim nds() As TreeNode = UcPMGroupRestrictions1.tvRestrictionByPMGroup.Nodes.Find(pNodeName, False)
            If nds.Length > 0 Then
                nds(0).BackColor = Color.Red
            End If
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Wayne Taylor (webtubbs)Commented:
By setting the second parameter to False, you are ignoring any child nodes, and only top level nodes will be looked at. Is that your wish?
farjack1Author Commented:
i tried with true as well but same length is comming 0. please suggest and property need to be set?
Wayne Taylor (webtubbs)Commented:
How are you loading your treeview? Can you show us the code?
farjack1Author Commented:
there is no problem in my tree, tree is populated correctly,
basically i am selected value from listbox and and finding  same value in treeview that value is in treeview i know that i can see that,

but the listbox is in seperate user control and treeview is in seperate user control, i am handling this with raiseevent is this cause any problem?
Wayne Taylor (webtubbs)Commented:
>>there is no problem in my tree, tree is populated correctly,

That is not what I asked for. I would like to see the code you use to populate the Treeview.
farjack1Author Commented:
this is my code

  Private Sub populateTree()

        Dim intX, j As Integer
        Dim strGID As String
        Dim resultList As ArrayList
        Dim strFID As String
        Dim strFName As String

        Dim objDataHelper As New DataHelper


        resultList = objDepartmentfundsDataHelper.getGF(CONSTUID)

        tv.Nodes.Add(STRID, "ROOT")
        tv.Nodes(STRID).ImageIndex = 0
        tv.Nodes(STRID).SelectedImageIndex = 0

        For intX = 0 To resultList.Count - 1

            strGID = CStr(CType(resultList.Item(intX), Groups).ID)

            tv.Nodes(0).Nodes.Add(strGID, CType(resultList.Item(intX), Groups).GName)
            tv.Nodes(0).Nodes(strGID).ImageIndex = 1
            tv.Nodes(0).Nodes(strGID).SelectedImageIndex = 1

            For j = 0 To CType(CType(resultList.Item(intX), Groups).GroupFunds.Item(0), GroupFunds).FID.Count - 1

                strFID = CStr(CType(CType(resultList.Item(intX), Groups).GroupFunds.Item(0), GroupFunds).FID.Item(j))
                strFName = CType(CType(resultList.Item(intX), Groups).GroupFunds.Item(0), GroupFunds).FundName.Item(j)

                tv.Nodes(0).Nodes(intX).Nodes.Add(CONST_F_IMAGE & strFID, strFName)
                tv.Nodes(0).Nodes(intX).Nodes(CONST_F_IMAGE & strFID).ImageIndex = 2
                tv.Nodes(0).Nodes(intX).Nodes(CONST_F_IMAGE & strFID).SelectedImageIndex = 2





    End Sub
farjack1Author Commented:
actually i have checked in seperate application, your code is working properly which you mentioned above, please advice what are the possibalities why it is not working with my code.

farjack1Author Commented:
now i am working on this b/c  my application is control based and the tree which i am trying to select the node is in seperate control and value is comming from seperate control when i am trying to find node

 Dim nds() As TreeNode = UcPMGroupRestrictions1.tvRestrictionByPMGroup.Nodes.Find(NodeName, True)

 node  length nds.Length is always zero when checked tree its node count is comming 0 although its populated.

Please give me solution
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.