첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
다운로드

▶ CustomTreeListNode.cs

using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;

namespace TestProject
{
    /// <summary>
    /// 커스텀 트리 리스트 노드
    /// </summary>
    public class CustomTreeListNode : TreeListNode
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 최소 높이
        /// </summary>
        private const int MINIMUM_HEIGHT = 5;

        /// <summary>
        /// 높이
        /// </summary>
        private int height;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 높이 - Height

        /// <summary>
        /// 높이
        /// </summary>
        public int Height
        {
            get
            {
                return this.height;
            }
            set
            {
                if(this.height == value || value < MINIMUM_HEIGHT)
                {
                    return;
                }

                this.height = value;

                Changed(NodeChangeTypeEnum.User1);
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - CustomTreeListNode(id, ownerNodeCollection)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="ownerNodeCollection">소유자 노드 컬렉션</param>
        public CustomTreeListNode(int id, TreeListNodes ownerNodeCollection) : base(id, ownerNodeCollection)
        {
            this.height = (ownerNodeCollection.TreeList as CustomTreeList).DefaultNodesHeight;
        }

        #endregion
    }
}

 

728x90

 

▶ CustomTreeList.cs

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, ownerNodeCollection, tag)

        /// <summary>
        /// 노드 생성하기
        /// </summary>
        /// <param name="nodeID">노드 ID</param>
        /// <param name="ownerNodeCollection">소유자 노드 컬렉션</param>
        /// <param name="tag">태그</param>
        /// <returns>노드</returns>
        protected override TreeListNode CreateNode(int nodeID, TreeListNodes ownerNodeCollection, object tag)
        {
            return new CustomTreeListNode(nodeID, ownerNodeCollection);
        }

        #endregion
        #region 노드 변경시 처리하기 (내부용) - InternalNodeChanged(node, nodeCollection, changeType)

        /// <summary>
        /// 노드 변경시 처리하기 (내부용)
        /// </summary>
        /// <param name="node">노드</param>
        /// <param name="nodeCollection">노드 컬렉션</param>
        /// <param name="changeType">변경 타입</param>
        protected override void InternalNodeChanged(TreeListNode node, TreeListNodes nodeCollection, NodeChangeTypeEnum changeType)
        {
            if(changeType == NodeChangeTypeEnum.User1)
            {
                LayoutChanged();
            }

            base.InternalNodeChanged(node, nodeCollection, changeType);
        }

        #endregion
        #region 노드 높이 계산 발생시키기 - RaiseCalcNodeHeight(node, nodeHeight)

        /// <summary>
        /// 노드 높이 계산 발생시키기
        /// </summary>
        /// <param name="node">노드</param>
        /// <param name="nodeHeight">노드 높이</param>
        protected override void RaiseCalcNodeHeight(TreeListNode node, ref int nodeHeight)
        {
            CustomTreeListNode customNode = node as CustomTreeListNode;

            if(customNode != null)
            {
                nodeHeight = customNode.Height;
            }
            else
            {
                base.RaiseCalcNodeHeight(node, ref nodeHeight);
            }
        }

        #endregion
    }
}

 

300x250

 

▶ MainForm.cs

using System;
using System.ComponentModel;

using DevExpress.Utils;
using DevExpress.XtraEditors;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            BindingList<Record> list = new BindingList<Record>();

            list.Add(new Record(0, -1, "Corporate Headquarters", 1000000, "Monterey"      ));
            list.Add(new Record(1,  0, "Sales and Marketing"   , 22000  , "San Francisco" ));
            list.Add(new Record(2,  0, "Finance"               , 40000  , "Monterey"      ));
            list.Add(new Record(3,  0, "Engineering"           , 1100000, "Monterey"      ));
            list.Add(new Record(4, -1, "Customer Services"     , 850000 , "Burlington, VT"));

            this.treeList.DataSource = list;

            this.treeList.Columns["Budget"].Format.FormatType   = FormatType.Numeric;
            this.treeList.Columns["Budget"].Format.FormatString = "c0";

            Load += Form_Load;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            this.treeList.ForceInitialize();

            this.treeList.ExpandAll();

            ((CustomTreeListNode)this.treeList.Nodes[0]).Height = 35;

            ((CustomTreeListNode)this.treeList.Nodes[0].Nodes[1]).Height = 35;
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,