How to change rad treeview node fore color for specific node ?

1 Answer 136 Views
Treeview
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
Aravind asked on 28 Aug 2023, 03:38 AM

Hi,
     How to change fore color for specific node ?  i have 3 level node and want to change fore color for 3rd level node only, below the code i used but not color not changed. 

        Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim filePath As String = "20230824.124217\20230824.1242174616\00001.tif" Dim filenode As String() = filePath.Split("\") Dim addNode As String = "" For i = 0 To filenode.Count - 1 If addNode = "" Then addNode = filenode(i) Else addNode = addNode & "\" & filenode(i) End If Dim searchKey As String = addNode Dim nodeExists As Boolean = CheckNodeExists(RadTreeView1.Nodes, searchKey) If Not nodeExists Then RadTreeView1.ForeColor = Color.Red Dim folderNode As RadTreeNode = New RadTreeNode() folderNode.ForeColor = System.Drawing.Color.Green RadTreeView1.AddNodeByPath(addNode) End If Next RadTreeView1.Update() RadTreeView1.Refresh() 
End Sub


Private Function CheckNodeExists(nodes As RadTreeNodeCollection, searchKey As String) As Boolean
        For Each node As RadTreeNode In nodes
            If node.FullPath = searchKey Then
                ' Node found
                Return True
            End If

            ' Recursively check child nodes
            If node.Nodes.Count > 0 Then
                If CheckNodeExists(node.Nodes, searchKey) Then
                    Return True
                End If
            End If
        Next

        ' Node not found
        Return False
    End Function

   

Pls reply asap.


Thanks and Regards
Aravind

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Aug 2023, 04:26 AM

Hi, Aravind,

The appropriate way to customize the visual node elements in RadTreeView is using the NodeFormatting event:

https://docs.telerik.com/devtools/winforms/controls/treeview/working-with-nodes/formatting-nodes 

The TreeNodeFormattingEventArgs give you access to the data Node and checking its Level property indicates the hierarchical level of the node that is currently being processed.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Aravind
Top achievements
Rank 2
Iron
Iron
Iron
commented on 29 Aug 2023, 07:55 AM

Ok , Thanks its working..
Tags
Treeview
Asked by
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or