■ TreeList 클래스의 NodesIterator 속성을 사용해 특정 노드 레벨 노드 수를 구하는 방법을 보여준다.
▶ CustomNodeOperation.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
using DevExpress.XtraTreeList.Nodes; using DevExpress.XtraTreeList.Nodes.Operations; namespace TestProject { /// <summary> /// 커스텀 노드 작업 /// </summary> public class CustomNodeOperation : TreeListOperation { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 노드 레벨 /// </summary> private int nodeLevel; /// <summary> /// 노드 수 /// </summary> private int nodeCount; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 노드 수 - NodeCount /// <summary> /// 노드 수 /// </summary> public int NodeCount { get { return this.nodeCount; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomNodeOperation(nodeLevel) /// <summary> /// 생성자 /// </summary> /// <param name="nodeLevel">노드 레벨</param> public CustomNodeOperation(int nodeLevel) : base() { this.nodeLevel = nodeLevel; this.nodeCount = 0; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 실행하기 - Execute(treeListNode) /// <summary> /// 실행하기 /// </summary> /// <param name="treeListNode">트리 리스트 노드</param> public override void Execute(TreeListNode treeListNode) { if(treeListNode.Level == nodeLevel) { nodeCount++; } } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using DevExpress.XtraTreeList; ... private TreeList treeList; ... CustomNodeOperation customNodeOperation = new CustomNodeOperation(2); this.treeList.NodesIterator.DoLocalOperation(customNodeOperation, this.treeList.Nodes); int nodeConunt = customNodeOperation.NodeCount; |