This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TreeListLookUpPopupForm.cs
148 lines (138 loc) · 6.01 KB
/
TreeListLookUpPopupForm.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
// Developer Express Code Central Example:
// How to create an analog of GridLookUpEdit with TreeList in a popup window
//
// In some cases, it is useful to display data within LookUpEdit in the
// hierarchical structure. This can be introduced by creating a custom editor –
// TreeListLookUpEdit. This example illustrates how to create such an editor. Here
// we have implemented the following features:
//
// - The
// RepositoryItemTreeListLookUpEdit.ValueMember and
// RepositoryItemTreeListLookUpEdit.DisplayMember properties. They are intended for
// the same functions as in a regular LookUpEdit/GridLookUpEdit.
// - The
// ProcessNewValue event is implemented like in LookUpEdit/GridLookUpEdit. This
// event is raised when an editor is validated and its display value does not exist
// within an inner TreeList.
// - The property SearchMode allows you to select one of
// the following modes:
// o OnlyInPopup. This mode is an analog of
// IncrementalSearch, but it also expands nodes if it is needed when you type a
// search text. This mode works only if a popup window is shown. o AutoComplete. In
// the Auto Completion mode, the text in the edit box is automatically completed if
// it matches a DisplayMember field value from drop-down nodes.
// o AutoFilter.
// This mode applies a filter to the DisplayMember column. Filter is formed when
// you type a text in the edit box. In addition, it opens a popup window and looks
// for nodes retaining paths to the root to show the context.
// For virtual data
// loading (on demand) in the inner TreeList you can handle its BeforeExpand event.
// Please refer to the following help articles:
//
// How to: Implement Dynamic
// Loading in Unbound Mode
// (ms-help://DevExpress.NETv12.1/DevExpress.WindowsForms/CustomDocument325.htm)
// Dynamic
// Data Loading via Events
// (ms-help://DevExpress.NETv12.1/DevExpress.WindowsForms/CustomDocument5560.htm)
// How
// to: Implement a Tree Structure for a Business Object
// (ms-help://DevExpress.NETv12.1/DevExpress.WindowsForms/CustomDocument5561.htm)
// to learn which virtual Modes TreeList supports.
//
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E4319
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraTreeList;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Filtering;
using DevExpress.XtraTreeList.Nodes;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraEditors.Controls;
namespace TreeListLookUp
{
class TreeListLookUpPopupForm : CustomBlobPopupForm
{
internal static int SmallIndent = 10;
public new RepositoryItemTreeListLookUpEdit Properties { get { return OwnerEdit.Properties as RepositoryItemTreeListLookUpEdit; } }
protected TreeList TreeList { get { return Properties.TreeList; } }
public TreeListLookUpPopupForm(PopupBaseEdit ownerEdit)
: base(ownerEdit)
{
this.TreeList.Bounds = new System.Drawing.Rectangle(SmallIndent/2, SmallIndent/2, 0, 0);
Controls.Add(TreeList);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
Size treeListSize = new Size();
treeListSize.Width = this.Size.Width - SmallIndent;
treeListSize.Height = this.Size.Height - this.ViewInfo.SizeBarRect.Height - SmallIndent;
TreeList.Size = treeListSize;
}
public override void ShowPopupForm()
{
base.ShowPopupForm();
if(Properties.SearchMode == SearchMode.OnlyInPopup)
TreeList.Focus();
}
protected override void Dispose(bool disposing)
{
TreeList.Parent = null;
base.Dispose(disposing);
}
protected override Size CalcFormSizeCore()
{
Size s = base.CalcFormSizeCore();
object blobSize = (OwnerEdit.Properties as RepositoryItemTreeListLookUpEdit).PropertiesStore["BlobSize"];
if (blobSize == null)
s.Width = Math.Max(DefaultEmptySize.Width, OwnerEdit.Width);
return s;
}
protected override object QueryResultValue()
{
return Properties.GetFocusedValue();
}
public override void ProcessKeyDown(KeyEventArgs e)
{
base.ProcessKeyDown(e);
string dispVal = (OwnerEdit as TreeListLookUpEdit).GetFilterText();
switch (e.KeyCode)
{
case Keys.Enter:
if (Properties.GetNodeByEditValue(dispVal) == null && dispVal != "")
{
ProcessNewValueEventArgs ee = new ProcessNewValueEventArgs(dispVal);
Properties.RaiseProcessNewValue(ee);
if (ee.Handled) { OwnerEdit.EditValue = Properties.GetNodeByText(dispVal)[Properties.ValueMember]; }
}
(this.OwnerEdit as TreeListLookUpEdit).HidePopup();
break;
case Keys.Down:
if (TreeList.Focused == false)
{
TreeList.Focus();
if (TreeList.Nodes.Count != 0)
if (TreeList.FocusedNode.NextNode != null && TreeList.FocusedNode.NextNode.Visible == true)
TreeList.FocusedNode = TreeList.FocusedNode.NextNode;
}
break;
case Keys.Up:
if (TreeList.Focused == false)
{
TreeList.Focus();
if (TreeList.Nodes.Count != 0)
if (TreeList.FocusedNode.PrevNode != null && TreeList.FocusedNode.PrevNode.Visible == true)
TreeList.FocusedNode = TreeList.FocusedNode.PrevNode;
}
break;
}
}
}
}