开发者

how to highlight individual items in treeview in WF

开发者 https://www.devze.com 2022-12-18 19:42 出处:网络
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开发者_运维知识库

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


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;
            }
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号