■ CheckedComboBoxEdit 클래스를 사용해 팝업에서 마우스를 드래그해 멀티 체크하는 방법을 보여준다.
▶ DataItem.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 |
namespace TestCheckedComboBoxEdit { /// <summary> /// 데이터 항목 /// </summary> public class DataItem { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion } } |
▶ MainForm.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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using DevExpress.Utils.Win; 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(); this.checkedComboBoxEdit1.Properties.AllowMultiSelect = true; this.checkedComboBoxEdit1.Properties.ValueMember = "ID"; this.checkedComboBoxEdit1.Properties.DisplayMember = "Name"; this.checkedComboBoxEdit1.Properties.DataSource = GetDataItemList(100); this.checkedComboBoxEdit1.Popup += checkedComboBoxEdit_Popup; this.checkedComboBoxEdit1.Closed += checkedComboBoxEdit_Closed; this.checkedComboBoxEdit2.Properties.AllowMultiSelect = true; this.checkedComboBoxEdit2.Properties.ValueMember = "ID"; this.checkedComboBoxEdit2.Properties.DisplayMember = "Name"; this.checkedComboBoxEdit2.Properties.DataSource = GetDataItemList(100); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 체크 콤보 박스 편집 팝업시 처리하기 - checkedComboBoxEdit_Popup(sender, e) /// <summary> /// 체크 콤보 박스 편집 팝업시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkedComboBoxEdit_Popup(object sender, EventArgs e) { IPopupControl popupControl = sender as IPopupControl; PopupContainerControl popupContainerControl = popupControl.PopupWindow.Controls.OfType<PopupContainerControl>().FirstOrDefault(); if(popupContainerControl != null) { CheckedListBoxControl checkedListBoxControl = popupContainerControl.Controls[0] as CheckedListBoxControl; checkedListBoxControl.MouseDown += checkedListBoxControl_MouseDown; checkedListBoxControl.MouseUp += checkedListBoxControl_MouseUp; } } #endregion #region 체크 콤보 박스 편집 팝업 닫는 경우 처리하기 - checkedComboBoxEdit_Closed(sender, e) /// <summary> /// 체크 콤보 박스 편집 팝업 닫는 경우 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkedComboBoxEdit_Closed(object sender, ClosedEventArgs e) { IPopupControl popupControl = sender as IPopupControl; PopupContainerControl popupContainerControl = popupControl.PopupWindow.Controls.OfType<PopupContainerControl>().FirstOrDefault(); if(popupContainerControl != null) { CheckedListBoxControl checkedListBoxControl = popupContainerControl.Controls[0] as CheckedListBoxControl; checkedListBoxControl.MouseDown -= checkedListBoxControl_MouseDown; checkedListBoxControl.MouseUp -= checkedListBoxControl_MouseUp; } } #endregion #region 체크 리스트 박스 컨트롤 마우스 DOWN 처리하기 - checkedListBoxControl_MouseDown(sender, e) /// <summary> /// 체크 리스트 박스 컨트롤 마우스 DOWN 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkedListBoxControl_MouseDown(object sender, MouseEventArgs e) { CheckedListBoxControl checkedListBoxControl = sender as CheckedListBoxControl; int index = checkedListBoxControl.IndexFromPoint(e.Location); if(index != -1) { if(checkedListBoxControl.HotItemIndex == index) { checkedListBoxControl.SetItemChecked(index, !checkedListBoxControl.GetItemChecked(index)); } } } #endregion #region 체크 리스트 박스 컨트롤 마우스 UP 처리하기 - checkedListBoxControl_MouseUp(sender, e) /// <summary> /// 체크 리스트 박스 컨트롤 마우스 UP 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkedListBoxControl_MouseUp(object sender, MouseEventArgs e) { CheckedListBoxControl checkedListBoxControl = sender as CheckedListBoxControl; if(checkedListBoxControl.SelectedIndices.Count > 0) { if(checkedListBoxControl.SelectedIndices[0] == 0 && checkedListBoxControl.SelectedIndices.Count > 1) { checkedListBoxControl.SetSelected(0, false); } checkedListBoxControl.ToggleSelectedItems(); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 데이터 항목 리스트 구하기 - GetDataItemList(itemCount) /// <summary> /// 데이터 항목 리스트 구하기 /// </summary> /// <param name="itemCount">항목 카운트</param> /// <returns>데이터 항목 리스트</returns> private List<DataItem> GetDataItemList(int itemCount) { List<DataItem> list = new List<DataItem>(); for(int i = 0; i < itemCount; i++) { list.Add(new DataItem { ID = i.ToString(), Name = "항목" + i.ToString() }); } return list; } #endregion } } |