-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComboBoxHideItemsHelper.cs
84 lines (82 loc) · 2.58 KB
/
ComboBoxHideItemsHelper.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
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Popup;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MyComboBoxEdit {
class ComboBoxHideItemsHelper : IDisposable {
private ComboBoxEdit _comboBox;
private List<int> _hiddenIndexes;
public ComboBoxEdit Owner {
get {
return _comboBox;
}
}
public List<int> HiddenIndexes {
get {
return _hiddenIndexes;
}
}
private MeasureItemEventHandler _itemMeasure;
public ComboBoxHideItemsHelper(ComboBoxEdit comboBox) {
this._itemMeasure = null;
this._hiddenIndexes = new List<int>();
this._comboBox = comboBox;
Init();
}
private void Init() {
if (_comboBox != null) {
if (_itemMeasure == null) {
_itemMeasure = new MeasureItemEventHandler(OnMeasureItem);
_comboBox.Properties.MeasureItem += _itemMeasure;
}
}
}
private void OnMeasureItem(object sender, MeasureItemEventArgs e) {
if (_hiddenIndexes.Contains(e.Index)) {
e.ItemHeight = 0;
e.ItemWidth = 0;
}
}
private void RefreshPopup() {
ComboBoxPopupListBoxForm popupForm = _comboBox.GetPopupEditForm();
if (popupForm != null) {
popupForm.Parent = null;
popupForm.Dispose();
}
}
public int Add(int value) {
int iResult = -1;
if (_comboBox == null || _hiddenIndexes.Contains(value)) return iResult;
try {
RefreshPopup();
_hiddenIndexes.Add(value);
iResult = _hiddenIndexes.Count - 1;
}
catch {
}
return iResult;
}
public void AddRange(int[] indexes) {
if (indexes == null) return;
for (int i = 0; i < indexes.Length; i++)
Add(indexes[i]);
}
public void Clear() {
_hiddenIndexes.Clear();
RefreshPopup();
}
public void Dispose() {
if (_comboBox != null) {
try {
_comboBox.Properties.MeasureItem -= _itemMeasure;
_comboBox = null;
_hiddenIndexes.Clear();
_hiddenIndexes = null;
}
catch {
}
}
}
}
}