-
Notifications
You must be signed in to change notification settings - Fork 3
/
Form1.cs
122 lines (109 loc) · 4.88 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
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
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;
namespace TestGridLookUpEditCSV {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
InitGrid();
RepositoryItemPopupContainerEdit ri = new RepositoryItemPopupContainerEdit();
ri.QueryResultValue += ri_QueryResultValue;
ri.EditValueChanged += ri_EditValueChanged;
ri.Popup += ri_Popup;
ri.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
PopupContainerControl popupControl = new PopupContainerControl();
popupControl.Controls.Add(popupGridControl1);
popupControl.Size = new System.Drawing.Size(500, 300);
ri.PopupControl = popupControl;
gridControl2.RepositoryItems.Add(ri);
gridView1.Columns["Name"].ColumnEdit = ri;
popupContainerEdit1.Properties.PopupControl = popupContainerControl1;
popupContainerEdit1.Properties.QueryResultValue += Properties_QueryResultValue;
popupContainerEdit1.Properties.EditValueChanged += Properties_EditValueChanged;
popupContainerEdit1.Properties.Popup += Properties_Popup;
}
void Properties_Popup(object sender, EventArgs e) {
PopupContainerEdit edit = sender as PopupContainerEdit;
if(!edit.IsPopupOpen)
edit.ShowPopup();
UpdateSelection(edit, popupGridView2);
}
void Properties_EditValueChanged(object sender, EventArgs e) {
PopupContainerEdit edit = sender as PopupContainerEdit;
UpdateSelection(edit, popupGridView2);
}
void Properties_QueryResultValue(object sender, DevExpress.XtraEditors.Controls.QueryResultValueEventArgs e) {
int[] selectedRows = popupGridView2.GetSelectedRows();
List<string> values = new List<string>();
foreach(int rowHandle in selectedRows) {
values.Add(popupGridView2.GetRowCellValue(rowHandle, "Name").ToString());
}
string csv = String.Join(", ", values);
e.Value = csv;
}
void ri_Popup(object sender, EventArgs e) {
PopupContainerEdit edit = sender as PopupContainerEdit;
UpdateSelection(edit, popupGridView1);
}
void ri_EditValueChanged(object sender, EventArgs e) {
PopupContainerEdit edit = sender as PopupContainerEdit;
if(!edit.IsPopupOpen)
edit.ShowPopup();
UpdateSelection(edit, popupGridView1);
}
void ri_QueryResultValue(object sender, DevExpress.XtraEditors.Controls.QueryResultValueEventArgs e) {
int[] selectedRows = popupGridView1.GetSelectedRows();
List<string> values = new List<string>();
foreach(int rowHandle in selectedRows) {
values.Add(popupGridView1.GetRowCellValue(rowHandle, "Name").ToString());
}
string csv = String.Join(", ", values);
e.Value = csv;
}
private void UpdateSelection(PopupContainerEdit edit, GridView view) {
view.BeginSelection();
view.ClearSelection();
if(edit != null)
if(edit.EditValue != null) {
edit.Focus();
List<int> selection = GetSelection(edit.EditValue.ToString().Split(new string[] { ", " }, StringSplitOptions.None), "Name", view);
foreach(int rowHandle in selection) {
view.SelectRow(rowHandle);
}
}
view.EndSelection();
}
private List<int> GetSelection(string[] values, string fieldName, GridView view) {
List<int> selection = new List<int>();
foreach(string val in values) {
for(int i = 0; i < view.RowCount; i++) {
if(view.GetRowCellValue(i, fieldName).ToString() == val)
selection.Add(i);
}
}
return selection;
}
private void InitGrid() {
popupGridControl1.DataSource = CreateList(5);
gridControl2.DataSource = CreateList(5);
popupGridControl2.DataSource = CreateList(5);
}
BindingList<Customer> CreateList(int count) {
BindingList<Customer> list = new BindingList<Customer>();
for(int i = 0; i < count; i++) {
list.Add(new Customer(i, "Name" + i, "Info" + i));
}
return list;
}
}
}