/
MainWindow.xaml.vb
60 lines (54 loc) · 3.3 KB
/
MainWindow.xaml.vb
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
Imports DevExpress.Spreadsheet
Imports DevExpress.Xpf.Editors.Settings
Imports DevExpress.Xpf.Spreadsheet
Imports System
Namespace WpfSpreadsheet_CustomCellEditors
Public Partial Class MainWindow
Inherits DevExpress.Xpf.Ribbon.DXRibbonWindow
Public Sub New()
Me.InitializeComponent()
Me.spreadsheetControl.LoadDocument("Documents\Document.xlsx", DocumentFormat.Xlsx)
AddHandler Me.spreadsheetControl.DocumentLoaded, AddressOf Me.spreadsheetControl1_DocumentLoaded
#Region "#CustomCellEdit"
AddHandler Me.spreadsheetControl.CustomCellEdit, AddressOf Me.spreadsheetControl1_CustomCellEdit
' ...
#End Region ' #CustomCellEdit
End Sub
Private Sub spreadsheetControl1_DocumentLoaded(ByVal sender As Object, ByVal e As EventArgs)
BindCustomEditors()
End Sub
Private Sub BindCustomEditors()
Dim worksheet As Worksheet = Me.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.
Dim dateEditRange As CellRange = 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.
Dim comboBoxRange As CellRange = 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.
Dim checkBoxRange As CellRange = 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.
Dim customRange As CellRange = worksheet("Table[Qty]")
worksheet.CustomCellInplaceEditors.Add(customRange, CustomCellInplaceEditorType.Custom, "MySpinEdit")
#End Region ' #PredefinedEditors
End Sub
#Region "#CustomCellEdit"
Private Sub spreadsheetControl1_CustomCellEdit(ByVal sender As Object, ByVal e As SpreadsheetCustomCellEditEventArgs)
' 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 AndAlso Equals(e.ValueObject.TextValue, "MySpinEdit") Then
' Create a SpinEdit in-place editor and assign it to a cell.
Dim settings As SpinEditSettings = New SpinEditSettings()
settings.MinValue = 1
settings.MaxValue = 1000
settings.IsFloatValue = False
e.EditSettings = settings
End If
End Sub
#End Region ' #CustomCellEdit
End Class
End Namespace