Articles in this section
Category / Section

How to control the FullRowSelect for individual nodes in WinForms TreeViewAdv?

1 min read

Customize the node background

This can be done by customizing the node background in the NodeBackGroundPaint event.

C#

private void treeViewAdv1_BeforeNodePaint(object sender, TreeNodeAdvPaintEventArgs e)
{
    e.Active = false;
}

private void treeViewAdv1_NodeBackgroundPaint(object sender,TreeNodeAdvPaintBackgroundEventArgs e)
{
    Pen p = new Pen(Color.Red);
    p.DashStyle = DashStyle.Dot;

    if (this.treeViewAdv1.Nodes[0] != e.Node)
    {
        if (e.Selected)
        {
            // Draw the RosyBrown background and dotted border.
            e.Graphics.FillRectangle(new SolidBrush(Color.RosyBrown), e.Bounds);
            e.Graphics.DrawRectangle(p, e.Bounds);
        }
    }
    else
    {
        if (e.Selected)
        {
            e.Graphics.FillRectangle(new SolidBrush(Color.RosyBrown), e.Node.TextBounds);
            e.Graphics.DrawRectangle(p, e.Node.TextBounds);
        }
    }

    e.Handled = true;
}

VB

Private Sub treeViewAdv1_BeforeNodePaint(ByVal sender As Object, ByVal e As TreeNodeAdvPaintEventArgs)
    e.Active = False
End Sub

Private Sub treeViewAdv1_NodeBackgroundPaint(ByVal sender As Object, ByVal e As TreeNodeAdvPaintBackgroundEventArgs)
    Dim p As Pen = New Pen(Color.Red)
    p.DashStyle = DashStyle.Dot

    If Me.treeViewAdv1.Nodes(0) <> e.Node Then
        If e.Selected Then
            ' Draw the RosyBrown background and dotted border.
            e.Graphics.FillRectangle(New SolidBrush(Color.RosyBrown), e.Bounds)
            e.Graphics.DrawRectangle(p, e.Bounds)
        End If
    Else
        If e.Selected Then
            e.Graphics.FillRectangle(New SolidBrush(Color.RosyBrown), e.Node.TextBounds)
            e.Graphics.DrawRectangle(p, e.Node.TextBounds)
        End If
    End If

    e.Handled = True
End Sub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied