views:

18

answers:

1

Hi all,

I'm building an application with treeview in windows form. I would like to change the background color/highlight individual items in the treeview based on some criteria. Does anyone have any suggestions on how to accomplish this?

Thank you very much!

Jason

A: 
void HighlightNodes(TreeNodeCollection nodes)
{
    if (nodes != null)
    {
        foreach (TreeNode node in nodes)
        {
            // Process sub-nodes
            if (node.Nodes.Count > 0)
            {
                HighlightNodes(node.Nodes);
            }

            if (criteriaIsMet)
            {
                node.BackColor = SystemColors.Highlight;
            }
            else
            {
                node.BackColor = Color.Empty;
            }
        }
    }
}
Yadyn