Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

highlight treeview node

i want to find treeview node and highlight with some color, please tell me the solution.  
0
farjack1
Asked:
farjack1
  • 6
  • 4
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Use the below code to highlight the node *named* "Node12".

Wayne
        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

0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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?
0
 
farjack1Author Commented:
i tried with true as well but same length is comming 0. please suggest and property need to be set?
0
 
Wayne Taylor (webtubbs)Commented:
How are you loading your treeview? Can you show us the code?
0
 
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?
 
0
 
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.
0
 
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

        tv.Nodes.Clear()

        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

            Next

        Next

        tv.ExpandAll()

        tv.Sort()

    End Sub
0
 
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.

Thanks
0
 
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now