[DEVEXPRESS/WINFORM] CheckedListBoxControl 클래스 : ItemChecking 이벤트를 사용해 항목 체크 제어하기
DevExpress/WinForm 2020. 2. 23. 20:37■ CheckedListBoxControl 클래스 : ItemChecking 이벤트를 사용해 항목 체크 제어하기
------------------------------------------------------------------------------------------------------------------------
▶ MainForm.cs
using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls;
namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent();
for(int i = 0; i < 10; i++) { this.checkedListBoxControl.Items.Add(new CheckedListBoxItem(i, "Item " + i.ToString())); }
this.checkedListBoxControl.ItemChecking += checkedListBoxControl_ItemChecking; this.checkedListBoxControl.ItemCheck += checkedListBoxControl_ItemCheck; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private
#region 체크 리스트 박스 컨트롤 항목 체크전 처리하기 - checkedListBoxControl_ItemChecking(sender, e)
/// <summary> /// 체크 리스트 박스 컨트롤 항목 체크전 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkedListBoxControl_ItemChecking(object sender, ItemCheckingEventArgs e) { CheckedListBoxControl checkedListBoxControl = sender as CheckedListBoxControl;
CheckedListBoxItem checkedListBoxItem = checkedListBoxControl.GetItem(e.Index) as CheckedListBoxItem;
if(checkedListBoxItem.Description == "Item 0") { XtraMessageBox.Show ( this, $"You cannot change the {checkedListBoxItem.Description} item check state.", "INFORMATION", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
e.Cancel = true; } }
#endregion #region 체크 리스트 박스 컨트롤 항목 체크시 처리하기 - checkedListBoxControl_ItemCheck(sender, e)
/// <summary> /// 체크 리스트 박스 컨트롤 항목 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkedListBoxControl_ItemCheck(object sender, ItemCheckEventArgs e) { CheckedListBoxControl checkedListBoxControl = sender as CheckedListBoxControl;
CheckedListBoxItem checkedListBoxItem = checkedListBoxControl.GetItem(e.Index) as CheckedListBoxItem;
XtraMessageBox.Show ( this, $"The {checkedListBoxItem.Description} item with the {checkedListBoxItem.Value} value is {checkedListBoxItem.CheckState}.", "INFORMATION", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information ); }
#endregion } }
|
------------------------------------------------------------------------------------------------------------------------
댓글을 달아 주세요