-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
141 lines (113 loc) · 5.27 KB
/
Form1.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
using DevExpress.Data.Controls.ExpressionEditor;
using DevExpress.Data.Filtering;
using DevExpress.Data.Filtering.Helpers;
using DevExpress.DataAccess.ExpressionEditor;
using DevExpress.DataAccess.UI.ExpressionEditor;
using DevExpress.DataAccess.UI.Native.ExpressionEditor;
using DevExpress.LookAndFeel;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace WindowsFormsApplication1 {
public partial class Form1 : XtraForm {
public class Product {
public Product(int productID, string productName, Category category) {
ProductID = productID;
ProductName = productName;
Category = category;
}
public int ProductID { get; }
public string ProductName { get; }
public int? SupplierID { get; set; }
public int? CategoryID { get; set; }
public short? UnitsOnOrder { get; set; }
public bool Discontinued { get; set; }
public Category Category { get; }
}
public class Category {
public int CategoryID { get; set; }
public string CategoryName { get; set; }
}
static List<Product> GetProductsList() {
var categoryBeverages = new Category { CategoryID = 1, CategoryName = "Beverages" };
var categoryConfections = new Category { CategoryID = 2, CategoryName = "Condiments" };
return new List<Product> {
new Product(1, "Chai", categoryBeverages),
new Product(2, "Chang", categoryBeverages),
new Product(3, "Coffee", categoryBeverages),
new Product(4, "Chocolade", categoryConfections),
new Product(5, "Maxilaku", categoryConfections),
new Product(6, "Valkoinen suklaa", categoryConfections),
};
}
public Form1() {
InitializeComponent();
this.gridControl1.DataSource = GetProductsList();
}
void gridView1_UnboundExpressionEditorCreated(object sender, DevExpress.XtraGrid.Views.Base.UnboundExpressionEditorEventArgs e) {
if(e.ExpressionEditorContext == null) {
return;
}
// Exclude "Now" from the list of available functions.
var nowFunction = e.ExpressionEditorContext.Functions.FirstOrDefault(fi => string.Equals(fi.Name, "now", StringComparison.OrdinalIgnoreCase));
if(nowFunction != null) {
e.ExpressionEditorContext.Functions.Remove(nowFunction);
}
// Uncomment the following line to use a custom color provider.
//e.ExpressionEditorContext.ColorProvider = new CustomColorProvider();
// Implement a custom criteria validator (e.g., to forbid using a specific function).
e.ExpressionEditorContext.CriteriaOperatorValidatorProvider = new ValidatorProvider();
// Disable capitalization of function names in expressions.
e.ExpressionEditorContext.OptionsBehavior.CapitalizeFunctionNames = false;
// Rename the "Columns" category to "Fields".
foreach(var columnInfo in e.ExpressionEditorContext.Columns) {
columnInfo.Category = "Fields";
}
// Uncomment the following line to use a custom Expression Editor view.
//e.ExpressionEditorView = new CustomExpressionEditorView(this.LookAndFeel, new CustomExpressionEditorControl());
}
}
class ValidatorProvider : ICriteriaOperatorValidatorProvider {
#region Implementation of ICriteriaOperatorValidatorProvider
public ErrorsEvaluatorCriteriaValidator GetCriteriaOperatorValidator(ExpressionEditorContext context) {
return new Validator(context);
}
#endregion
}
class Validator : CriteriaOperatorValidator {
public Validator(ExpressionEditorContext context)
: base(context, supportsAggregates: true) {
}
#region Overrides of CriteriaOperatorValidator
public override void Visit(FunctionOperator theOperator) {
if (theOperator.OperatorType == FunctionOperatorType.Now) {
this.errors.Add(new CriteriaValidatorError("Invalid function: now()"));
}
base.Visit(theOperator);
}
#endregion
}
class CustomColorProvider : IExpressionEditorColorProvider {
public Color GetColorForElement(ExpressionElementKind elementKind) {
if (elementKind == ExpressionElementKind.Column)
return Color.BlueViolet;
if (elementKind == ExpressionElementKind.Function)
return Color.Brown;
return Color.Azure;
}
}
public class CustomExpressionEditorView : ExpressionEditorView {
public CustomExpressionEditorView(UserLookAndFeel lookAndFeel, ExpressionEditorControl expressionEditor)
: base(lookAndFeel, expressionEditor) {
}
}
public class CustomExpressionEditorControl : ExpressionEditorControl {
#region Overrides of ExpressionEditorControl
protected override ExpressionDocumentationControl CreateDocumentationControl() {
return null;
}
#endregion
}
}