-
Notifications
You must be signed in to change notification settings - Fork 0
/
CellColorHelper.cs
74 lines (64 loc) · 1.95 KB
/
CellColorHelper.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
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class CellColorHelper
{
Dictionary<MyGridCell, Color> colors = new Dictionary<MyGridCell, Color>();
private readonly GridView _View;
/// <summary>
/// Initializes a new instance of the CellColorHelper class.
/// </summary>
public CellColorHelper(GridView view)
{
_View = view;
_View.RowCellStyle += _View_RowCellStyle;
}
void _View_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
Color color = GetCellColor(new MyGridCell(e.RowHandle, e.Column));
if (color.IsEmpty)
return;
e.Appearance.BackColor = color;
}
public Color GetCellColor(MyGridCell cell)
{
Color c = Color.Empty;
if (colors.TryGetValue(cell, out c))
return c;
return Color.Empty;
}
public void SetCellColor(int rowHandle, GridColumn column, Color value)
{
SetCellColor(new MyGridCell(rowHandle, column), value);
}
public void SetCellColor(MyGridCell cell, Color value)
{
colors[cell] = value;
_View.RefreshRowCell(cell.RowHandle, cell.Column);
}
}
public class MyGridCell:GridCell
{
public MyGridCell(int rowHandle, GridColumn column)
: base(rowHandle, column)
{
}
public override int GetHashCode()
{
return Column.GetHashCode() + RowHandle.GetHashCode();
}
public override bool Equals(object obj)
{
return Equals(obj as GridCell);
}
}
}