[DEVEXPRESS/WINFORM] PropertyGridControl 클래스 : CustomPropertyDescriptors 이벤트를 사용해 속성 정렬하기
DevExpress/WinForm 2020. 5. 3. 00:58728x90
반응형
728x170
▶ MainForm.cs
using System;
using DevExpress.XtraEditors;
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Events;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region Field
/// <summary>
/// 커스텀 정렬 허용 여부
/// </summary>
private bool allowCustomSorting = false;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.propertyGridControl.SelectedObject = new CustomClass()
{
Property1 = "one",
Property2 = "two",
Property3 = "three",
Property4 = "four",
Property5 = "five"
};
this.propertyGridControl.CustomPropertyDescriptors += propertyGridControl_CustomPropertyDescriptors;
this.button.Click += button_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 속성 그리드 컨트롤 속성 설명자 커스텀 설정하기 - propertyGridControl_CustomPropertyDescriptors(sender, e)
/// <summary>
/// 속성 그리드 컨트롤 속성 설명자 커스텀 설정하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void propertyGridControl_CustomPropertyDescriptors(object sender, CustomPropertyDescriptorsEventArgs e)
{
if(this.allowCustomSorting && e.Context.PropertyDescriptor == null)
{
e.Properties = e.Properties.Sort(new string[] { "Property5", "Property4", "Property3", "Property2", "Property1" });
}
}
#endregion
#region 버튼 클릭시 처리하기 - button_Click(sender, e)
/// <summary>
/// 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void button_Click(object sender, EventArgs e)
{
this.allowCustomSorting = !this.allowCustomSorting;
if(this.allowCustomSorting)
{
this.propertyGridControl.OptionsBehavior.PropertySort = PropertySort.NoSort;
}
else
{
this.propertyGridControl.OptionsBehavior.PropertySort = PropertySort.Alphabetical;
}
this.propertyGridControl.Refresh();
this.propertyGridControl.RetrieveFields();
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요