C# 判斷樹形結構選中狀態(一級選單選中二級選單必須全選)
阿新 • • 發佈:2019-01-09
/// <summary> /// 檢查樹節點狀態,一級選單選中,二級選單必須全選 /// </summary> /// <param name="nodes">Nodes集合</param> public static void CheckTreeNodeCheckedStatus(TreeNodeCollection Nodes) { TreeNodeCollection tempNodes = Nodes; for (int i = 0; i < tempNodes.Count ; i++) { if (tempNodes[i].Checked) { CheckTreeNodeCheckedStatus(tempNodes[i].Nodes); if(tempNodes[i].Nodes.Count == 0) { recursionCount++; } else if(tempNodes[i].Nodes.Count != recursionCount) { Console.WriteLine(string.Format("選中的節點中包含不合格的樹節點:{0}", tempNodes[i].Text)); } } } }