/
Form1.cs
100 lines (85 loc) · 4.3 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors;
using DevExpress.XtraSpreadsheet;
using DevExpress.Spreadsheet;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
RepositoryItemPopupContainerEdit rePopupContainer = propertyGridControl1.RepositoryItems.Add("PopupContainerEdit") as RepositoryItemPopupContainerEdit;
rePopupContainer.PopupControl = popupContainerControl1;
rePopupContainer.QueryPopUp += new CancelEventHandler(rePopupContainer_QueryPopUp);
rePopupContainer.QueryResultValue += new DevExpress.XtraEditors.Controls.QueryResultValueEventHandler(rePopupContainer_QueryResultValue);
propertyGridControl1.DefaultEditors.Add(typeof(DataTable), rePopupContainer);
rePopupContainer.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(rePopupContainer_CustomDisplayText);
MyObject newObject = new MyObject();
propertyGridControl1.SelectedObject = newObject;
gridControl1.DataSource = new BindingList<MyObject>() { newObject };
gridControl1.ForceInitialize();
gridView1.Columns["MySpreadSheet"].ColumnEdit = rePopupContainer;
}
void rePopupContainer_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e) {
e.DisplayText = "(table data)";
}
void rePopupContainer_QueryResultValue(object sender, DevExpress.XtraEditors.Controls.QueryResultValueEventArgs e) {
DataTable currentTable = (propertyGridControl1.SelectedObject as MyObject).MySpreadSheet;
if(currentTable == null) {
currentTable = new DataTable();
(propertyGridControl1.SelectedObject as MyObject).MySpreadSheet = currentTable;
}
currentTable.Clear();
currentTable.Columns.Clear();
SpreadsheetControl spreadSheet = (sender as PopupContainerEdit).Properties.PopupControl.Controls[0] as SpreadsheetControl;
Worksheet workSheet = spreadSheet.Document.Worksheets[0];
CellRange usedRange = workSheet.GetUsedRange();
for(int i = 0; i < usedRange.ColumnCount; i++) {
currentTable.Columns.Add("Column" + i.ToString());
}
for(int i = 0; i < usedRange.RowCount; i++) {
DataRow newRow = currentTable.NewRow();
for (int j = 0; j < usedRange.ColumnCount; j++)
{
newRow[j] = workSheet.Cells[i,j].DisplayText;
}
currentTable.Rows.Add(newRow);
}
}
void rePopupContainer_QueryPopUp(object sender, CancelEventArgs e) {
DataTable currentTable = (propertyGridControl1.SelectedObject as MyObject).MySpreadSheet;
if(currentTable != null) {
SpreadsheetControl spreadSheet = (sender as PopupContainerEdit).Properties.PopupControl.Controls[0] as SpreadsheetControl;
Worksheet workSheet = spreadSheet.Document.Worksheets[0];
for(int i = 0; i < currentTable.Columns.Count; i++) {
for(int j = 0; j < currentTable.Rows.Count; j++) {
workSheet.Cells[j, i].Value = currentTable.Rows[j][i].ToString();
}
}
}
}
}
public class MyObject {
public MyObject() {
Name = "Some name";
MySpreadSheet = new DataTable();
for(int i = 0; i < 5; i++) {
MySpreadSheet.Columns.Add("Value" + i.ToString(), typeof(int));
}
Random myRand = new Random();
for(int i = 0; i < 20; i++) {
MySpreadSheet.Rows.Add(myRand.Next(1, 100), myRand.Next(1, 100), myRand.Next(1, 100), myRand.Next(1, 100), myRand.Next(1, 100));
}
}
public string Name { get; set; }
public DataTable MySpreadSheet {get; set;}
}
}