TreeView for WinForms | ComponentOne
In This Topic
    Styling a Single Node or Node Cell
    In This Topic

    TreeView allows you to change the style of a single node or node cell by using the ApplyNodeStyles and the ApplyNodeCellStyles event of C1TreeView. The ApplyNodeStyles event occurs when you apply styles to a node, while the ApplyNodeCellStyles event occurs when you apply styles to a cell of a node.

    To customize a node or a node cell, you first need to specify the node level by using the Level property of the C1TreeNode class. And then you can use the NodeStyles or the NodeCellStyles property provided by the C1TreeViewNodeStylesEventArgs and the C1TreeViewNodeCellStylesEventArgs class respectively, to access properties of NodeCellStyle and TreeNodeCellStyles classes. Using various properties provided by these classes, such as BackColor, ForeColor, Default, and others, you can customize a specific node or node cell.

    The following code snippet shows the implementation.

    Private Sub C1TreeView1_ApplyNodeStyles(sender As Object, e As C1TreeViewNodeStylesEventArgs)
    
        If (e.Node.Level = 1) OrElse (e.Node.Level = 2) Then
            e.NodeStyles.[Default].BackColor = Color.Aqua
        End If
    End Sub
    Private Sub C1TreeView1_ApplyNodeCellStyles(sender As Object, e As C1.Win.TreeView.C1TreeViewNodeCellStylesEventArgs)
    
        If e.Node.Level = 0 AndAlso e.ColumnIndex = 0 Then
            e.NodeCellStyles.[Default].BackColor = Color.LightGray
        End If
    End Sub
    
    private void C1TreeView1_ApplyNodeStyles(object sender, C1.Win.TreeView.C1TreeViewNodeStylesEventArgs e)
    {
        if ((e.Node.Level == 1)||(e.Node.Level == 2))
            e.NodeStyles.Default.BackColor = Color.Aqua;
    }
    
    private void C1TreeView1_ApplyNodeCellStyles(object sender, C1.Win.TreeView.C1TreeViewNodeCellStylesEventArgs e)
    {
    
        if (e.Node.Level == 0 && e.ColumnIndex == 0)
            e.NodeCellStyles.Default.BackColor = Color.LightGray;
    }
    

    Node styling