/
RowStateHelper.cs
97 lines (83 loc) · 2.87 KB
/
RowStateHelper.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
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace WindowsApplication1
{
[DesignerCategory("")]
[Designer("")]
public class RowStateHelper : Component
{
private AppearanceObject _AppearanceDisabledRow;
private List<int> _DisabledRows;
private GridView _GridView;
public RowStateHelper()
{
_DisabledRows = new List<int>();
_AppearanceDisabledRow = new AppearanceObject();
AppearanceDisabledRow.Changed += _AppearanceDisabledRow_Changed;
}
void _AppearanceDisabledRow_Changed(object sender, EventArgs e)
{
if (GridView == null) return;
for (int i = 0; i < DisabledRows.Count; i++)
{
GridView.RefreshRow(GridView.GetRowHandle(DisabledRows[i]));
}
}
private void SubscribeEvents(GridView view)
{
if (view != null)
{
view.RowCellStyle += view_RowCellStyle;
view.ShowingEditor += view_ShowingEditor;
}
}
private void UnSubscribeEvents(GridView view)
{
if (view != null)
{
view.RowCellStyle -= view_RowCellStyle;
view.ShowingEditor -= view_ShowingEditor;
}
}
void view_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
Console.WriteLine(DateTime.Now.Millisecond);
if (IsRowDisabled(GridView.GetDataSourceRowIndex(e.RowHandle)))
e.Appearance.Assign(AppearanceDisabledRow);
}
void view_ShowingEditor(object sender, CancelEventArgs e)
{
e.Cancel = IsRowDisabled(GridView.GetDataSourceRowIndex(GridView.FocusedRowHandle));
}
public void DisableRow(int dataSourceRowIndex)
{
DisabledRows.Add(dataSourceRowIndex);
}
public void EnableRow(int dataSourceRowIndex)
{
while (IsRowDisabled(dataSourceRowIndex))
{
DisabledRows.Remove(dataSourceRowIndex);
}
}
public bool IsRowDisabled(int dataSourceRowIndex)
{
return DisabledRows.Contains(dataSourceRowIndex);
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public AppearanceObject AppearanceDisabledRow {
get { return _AppearanceDisabledRow; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<int> DisabledRows {
get { return _DisabledRows; }
}
public GridView GridView {
get { return _GridView; }
set { UnSubscribeEvents(_GridView); _GridView = value; SubscribeEvents(value); }
}
}
}