■ TreeList 클래스에서 커스텀 노드를 사용하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using DevExpress.XtraTreeList; ... private TreeList treeList; ... this.treeList = new CustomTreeList(); ... ((CustomTreeListNode)this.treeList2.Nodes[0]).Height = 35; |
▶ CustomTreeListNode.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 |
using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Nodes; namespace TestProject { /// <summary> /// 커스텀 트리 리스트 노드 /// </summary> public class CustomTreeListNode : TreeListNode { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 최소 높이 /// </summary> private const int minHeight = 5; /// <summary> /// 높이 /// </summary> private int height; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 높이 - Height /// <summary> /// 높이 /// </summary> public int Height { get { return this.height; } set { if(Height == value || value < minHeight) { return; } height = value; Changed(NodeChangeTypeEnum.User1); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomTreeListNode(id, ownerNode) /// <summary> /// 생성자 /// </summary> /// <param name="id">ID</param> /// <param name="ownerNode">소유자 노드</param> public CustomTreeListNode(int id, TreeListNodes ownerNode) : base(id, ownerNode) { this.height = (ownerNode.TreeList as CustomTreeList).DefaultNodesHeight; } #endregion } } |
▶ CustomTreeList.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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Nodes; namespace TestProject { /// <summary> /// 생성자 /// </summary> public class CustomTreeList : TreeList { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 디폴트 노드들 높이 - DefaultNodesHeight /// <summary> /// 디폴트 노드들 높이 /// </summary> public virtual int DefaultNodesHeight { get { return 18; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomTreeList() /// <summary> /// 생성자 /// </summary> public CustomTreeList() : base() { OptionsBehavior.AutoNodeHeight = false; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 노드 생성하기 - CreateNode(nodeID, ownerNode, tag) /// <summary> /// 노드 생성하기 /// </summary> /// <param name="nodeID">노드 ID</param> /// <param name="ownerNode">소유자 노드</param> /// <param name="tag">태그</param> /// <returns>노드</returns> protected override TreeListNode CreateNode(int nodeID, TreeListNodes ownerNode, object tag) { return new CustomTreeListNode(nodeID, ownerNode); } #endregion #region 내부 노드 변경시 처리하기 - InternalNodeChanged(sourceNode, nodeChangeType) /// <summary> /// 내부 노드 변경시 처리하기 /// </summary> /// <param name="sourceNode">소스노드</param> /// <param name="nodeChangeType">노드 변경 타입</param> protected override void InternalNodeChanged(TreeListNode sourceNode, NodeChangeTypeEnum nodeChangeType) { if(nodeChangeType == NodeChangeTypeEnum.User1) { LayoutChanged(); } base.InternalNodeChanged(sourceNode, nodeChangeType); } #endregion #region 노드 높이 계산시 처리하기 - RaiseCalcNodeHeight(sourceNode, nodeHeight) /// <summary> /// 노드 높이 계산시 처리하기 /// </summary> /// <param name="sourceNode">소스 노드</param> /// <param name="nodeHeight">노드 높이</param> protected override void RaiseCalcNodeHeight(TreeListNode sourceNode, ref int nodeHeight) { CustomTreeListNode customTreeListNode = sourceNode as CustomTreeListNode; if(customTreeListNode != null) { nodeHeight = customTreeListNode.Height; } else { base.RaiseCalcNodeHeight(sourceNode, ref nodeHeight); } } #endregion } } |