-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormDifferentSources.cs
126 lines (111 loc) · 4.41 KB
/
FormDifferentSources.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
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FilterLookUpsEditForm
{
public partial class FormDifferentSources : Form
{
public FormDifferentSources()
{
InitializeComponent(); gridControl1.DataSource = GetData(10);
RepositoryItemLookUpEdit ritem = new RepositoryItemLookUpEdit(); // for Type column
ritem.DataSource = GetLookData();
ritem.ValueMember = "ID";
ritem.DisplayMember = "Type";
ritemFruits.ValueMember = "ID";
ritemFruits.DisplayMember = "Fruit";
ritemFruits.DataSource = GetFruits();
ritemVegetables.ValueMember = "ID";
ritemVegetables.DisplayMember = "Vegetable";
ritemVegetables.DataSource = GetVegetables();
gridView1.Columns["Type"].ColumnEdit = ritem;
gridView1.Columns["Value"].ColumnEdit = ritemVegetables;
gridView1.OptionsBehavior.EditingMode = GridEditingMode.EditFormInplace;
gridView1.CustomRowCellEdit += new CustomRowCellEditEventHandler(gridView1_CustomRowCellEdit);
gridView1.EditFormPrepared += new EditFormPreparedEventHandler(gridView1_EditFormPrepared);
}
RepositoryItemLookUpEdit ritemVegetables = new RepositoryItemLookUpEdit();
RepositoryItemLookUpEdit ritemFruits = new RepositoryItemLookUpEdit();
LookUpEdit filteredLookUp;
LookUpEdit baseLookUp;
void gridView1_EditFormPrepared(object sender, EditFormPreparedEventArgs e)
{
baseLookUp = e.BindableControls["Type"] as LookUpEdit;
filteredLookUp = e.BindableControls["Value"] as LookUpEdit;
if (baseLookUp != null && filteredLookUp != null)
{
baseLookUp.EditValueChanged -= baseLookUp_EditValueChanged;
baseLookUp.EditValueChanged += baseLookUp_EditValueChanged;
}
}
void baseLookUp_EditValueChanged(object sender, EventArgs e)
{
string type = baseLookUp.EditValue.ToString();
if (type == "0") filteredLookUp.Properties.Assign(ritemVegetables);
if (type == "1") filteredLookUp.Properties.Assign(ritemFruits);
}
void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "Value")
{
GridView view = sender as GridView;
string type = view.GetRowCellValue(e.RowHandle, "Type").ToString();
if (type == "0") e.RepositoryItem = ritemVegetables;
if (type == "1") e.RepositoryItem = ritemFruits;
}
}
#region Data
DataTable GetLookData() // for LookUpEdit from the Type column
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Type", typeof(string));
dt.Rows.Add(0, "Vegetable");
dt.Rows.Add(1, "Fruit");
return dt;
}
DataTable GetVegetables()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Vegetable", typeof(string));
dt.Rows.Add(0, "Tomato");
dt.Rows.Add(1, "Onion");
dt.Rows.Add(2, "Pepper");
dt.Rows.Add(3, "Cucumber");
dt.Rows.Add(4, "Pumpkin");
return dt;
}
DataTable GetFruits()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Fruit", typeof(string));
dt.Rows.Add(0, "Apple");
dt.Rows.Add(1, "Banana");
dt.Rows.Add(2, "Orange");
dt.Rows.Add(3, "Peach");
dt.Rows.Add(4, "Mango");
return dt;
}
DataTable GetData(int rows) // for GridControl
{
DataTable dt = new DataTable();
dt.Columns.Add("Type", typeof(int));
dt.Columns.Add("Value", typeof(int));
for (int i = 0; i < rows; i++)
dt.Rows.Add(i % 2, i % 5);
return dt;
}
#endregion
}
}