/
MyPopupContainerEdit.cs
130 lines (123 loc) · 5.37 KB
/
MyPopupContainerEdit.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
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors;
using System.ComponentModel;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors.Repository;
namespace DXSample {
[UserRepositoryItem("Register")]
public class RepositoryItemMyPopupContainerEdit : RepositoryItemPopupContainerEdit {
static RepositoryItemMyPopupContainerEdit() {
Register();
}
ImageListBoxControl imageListBox;
public RepositoryItemMyPopupContainerEdit() {
PopupContainerControl popupControl = new PopupContainerControl();
imageListBox = new ImageListBoxControl();
imageListBox.Dock = System.Windows.Forms.DockStyle.Fill;
imageListBox.HotTrackItems = true;
imageListBox.HotTrackSelectMode = HotTrackSelectMode.SelectItemOnClick;
popupControl.Controls.Add(imageListBox);
PopupControl = popupControl;
TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
}
[AttributeProvider(typeof(IListSource)), DefaultValue(null), RefreshProperties(RefreshProperties.Repaint), Category("Data")]
public object DataSource {
get {
return imageListBox.DataSource;
}
set {
imageListBox.DataSource = value;
}
}
protected internal ImageListBoxControl ListBox {
get {
return imageListBox;
}
}
[Category(CategoryName.Appearance), DefaultValue(null),
TypeConverter(typeof(DevExpress.Utils.Design.ImageCollectionImagesConverter))]
public object ImageList {
get {
return imageListBox.ImageList;
}
set {
imageListBox.ImageList = value;
}
}
[Category(CategoryName.Data), DefaultValue(""),
TypeConverter("DevExpress.XtraEditors.Design.DataMemberTypeConverter, " + AssemblyInfo.SRAssemblyEditorsDesign)]
public string ImageIndexMember {
get { return imageListBox.ImageIndexMember; }
set {
imageListBox.ImageIndexMember = value;
}
}
[Category(CategoryName.Data), DefaultValue(""),
TypeConverter("DevExpress.XtraEditors.Design.DataMemberTypeConverter, " + AssemblyInfo.SRAssemblyEditorsDesign)]
public string DisplayMember {
get { return imageListBox.DisplayMember; }
set {
imageListBox.DisplayMember = value;
}
}
[Category(CategoryName.Data), DefaultValue(""),
TypeConverter("DevExpress.XtraEditors.Design.DataMemberTypeConverter, " + AssemblyInfo.SRAssemblyEditorsDesign)]
public string ValueMember {
get { return imageListBox.ValueMember; }
set {
imageListBox.ValueMember = value;
}
}
internal const string EditorName = "MyPopupContainerEdit";
public static void Register() {
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(EditorName, typeof(MyPopupContainerEdit),
typeof(RepositoryItemMyPopupContainerEdit), typeof(DevExpress.XtraEditors.ViewInfo.PopupContainerEditViewInfo),
new DevExpress.XtraEditors.Drawing.ButtonEditPainter(), true, null, typeof(DevExpress.Accessibility.PopupEditAccessible)));
}
public override string EditorTypeName {
get { return EditorName; }
}
public override void Assign(RepositoryItem item) {
base.Assign(item);
if (item is RepositoryItemMyPopupContainerEdit) {
imageListBox = ((RepositoryItemMyPopupContainerEdit)item).ListBox;
}
}
}
public class MyPopupContainerEdit : PopupContainerEdit {
static MyPopupContainerEdit() {
RepositoryItemMyPopupContainerEdit.Register();
}
public MyPopupContainerEdit() {}
public override string EditorTypeName {
get { return RepositoryItemMyPopupContainerEdit.EditorName; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemMyPopupContainerEdit Properties {
get { return base.Properties as RepositoryItemMyPopupContainerEdit; }
}
public override void ShowPopup() {
Properties.ListBox.SelectedValue = EditValue;
base.ShowPopup();
}
void ListBox_SelectedIndexChanged(object sender, EventArgs e) {
EditValue = Properties.ListBox.SelectedValue;
}
protected override void OnPopupShown() {
base.OnPopupShown();
Properties.ListBox.SelectedIndexChanged += new EventHandler(ListBox_SelectedIndexChanged);
Properties.ListBox.MouseDown += new System.Windows.Forms.MouseEventHandler(ListBox_MouseDown);
}
void ListBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
ClosePopup();
EditValue = Properties.ListBox.SelectedValue;
}
public override void ClosePopup() {
base.ClosePopup();
Properties.ListBox.SelectedIndexChanged -= new EventHandler(ListBox_SelectedIndexChanged);
Properties.ListBox.MouseDown -= new System.Windows.Forms.MouseEventHandler(ListBox_MouseDown);
}
}
}