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

TestProject.zip
다운로드

▶ MainForm.cs

using System.ComponentModel;

using DevExpress.XtraEditors;
using DevExpress.XtraVerticalGrid.Events;

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

        #region 생성자 - MainForm()

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

            this.propertyGridControl.CustomPropertyDescriptors += propertyGridControl_CustomPropertyDescriptors;

            this.propertyGridControl.SelectedObject = this.propertyGridControl;

            this.propertyGridControl.GetRowByFieldName("Size"    ).Expanded = true;
            this.propertyGridControl.GetRowByFieldName("Location").Expanded = true;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 속성 그리드 컨트롤 속성 설명자 커스텀 설정하기 - propertyGridControl_CustomPropertyDescriptors(sender, e)

        /// <summary>
        /// 속성 그리드 컨트롤 속성 설명자 커스텀 설정하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void propertyGridControl_CustomPropertyDescriptors(object sender, CustomPropertyDescriptorsEventArgs e)
        {
            if(e.Context.PropertyDescriptor == null)
            {
                PropertyDescriptorCollection targetCollection = new PropertyDescriptorCollection(null);

                AddPropertyDescriptor(e.Properties, targetCollection, "Dock"               );
                AddPropertyDescriptor(e.Properties, targetCollection, "Size"               );
                AddPropertyDescriptor(e.Properties, targetCollection, "Location"           );
                AddPropertyDescriptor(e.Properties, targetCollection, "NonexistentProperty");

                e.Properties = targetCollection;
            }

            if(e.Context.PropertyDescriptor != null && e.Context.PropertyDescriptor.Name == "Size")
            {
                PropertyDescriptorCollection targetCollection = new PropertyDescriptorCollection(null);

                AddPropertyDescriptor(e.Properties, targetCollection, "Width" );
                AddPropertyDescriptor(e.Properties, targetCollection, "Height");

                e.Properties = targetCollection;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 속성 설명자 추가하기 - AddPropertyDescriptor(source, target, string name)

        /// <summary>
        /// 속성 설명자 추가하기
        /// </summary>
        /// <param name="source">소스 컬렉션</param>
        /// <param name="target">타겟 컬렉션</param>
        /// <param name="name">명칭</param>
        private void AddPropertyDescriptor(PropertyDescriptorCollection source, PropertyDescriptorCollection target, string name)
        {
            PropertyDescriptor descriptor = source[name];

            if(descriptor == null)
            {
                return;
            }

            target.Add(descriptor);
        }

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

댓글을 달아 주세요