-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.xaml.cs
69 lines (60 loc) · 3.24 KB
/
MainWindow.xaml.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
using DevExpress.Spreadsheet;
using DevExpress.Xpf.Editors.Settings;
using DevExpress.Xpf.Spreadsheet;
using System;
namespace WpfSpreadsheet_CustomCellEditors
{
public partial class MainWindow : DevExpress.Xpf.Ribbon.DXRibbonWindow
{
public MainWindow()
{
InitializeComponent();
spreadsheetControl.LoadDocument("Documents\\Document.xlsx", DocumentFormat.Xlsx);
spreadsheetControl.DocumentLoaded += spreadsheetControl1_DocumentLoaded;
#region #CustomCellEdit
spreadsheetControl.CustomCellEdit += spreadsheetControl1_CustomCellEdit;
// ...
#endregion #CustomCellEdit
}
private void spreadsheetControl1_DocumentLoaded(object sender, EventArgs e)
{
BindCustomEditors();
}
private void BindCustomEditors()
{
Worksheet worksheet = spreadsheetControl.Document.Worksheets["Sales report"];
#region #PredefinedEditors
// Use a date editor as the in-place editor for cells located in the "Order Date" column of the worksheet table.
CellRange dateEditRange = worksheet["Table[Order Date]"];
worksheet.CustomCellInplaceEditors.Add(dateEditRange, CustomCellInplaceEditorType.DateEdit);
// Use a combo box editor as the in-place editor for cells located in the "Category" column of the worksheet table.
// The editor's items are obtained from a cell range in the current worksheet.
CellRange comboBoxRange = worksheet["Table[Category]"];
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet["J3:J9"]));
// Use a check editor as the in-place editor for cells located in the "Discount" column of the worksheet table.
CellRange checkBoxRange = worksheet["Table[Discount]"];
worksheet.CustomCellInplaceEditors.Add(checkBoxRange, CustomCellInplaceEditorType.CheckBox);
// Use the custom control (SpinEdit) as the in-place editor for cells located in the "Quantity" column of the worksheet table.
// To provide the required editor, handle the CustomCellEdit event.
CellRange customRange = worksheet["Table[Qty]"];
worksheet.CustomCellInplaceEditors.Add(customRange, CustomCellInplaceEditorType.Custom, "MySpinEdit");
#endregion #PredefinedEditors
}
#region #CustomCellEdit
private void spreadsheetControl1_CustomCellEdit(object sender, SpreadsheetCustomCellEditEventArgs e)
{
// Specify a type of the custom editor assigned to cells of the "Quantity" table column.
// To identify the custom editor, use a value of ValueObject associated with it.
if (e.ValueObject.IsText && e.ValueObject.TextValue == "MySpinEdit")
{
// Create a SpinEdit in-place editor and assign it to a cell.
SpinEditSettings settings = new SpinEditSettings();
settings.MinValue = 1;
settings.MaxValue = 1000;
settings.IsFloatValue = false;
e.EditSettings = settings;
}
}
#endregion #CustomCellEdit
}
}