/
CellColorHelper.vb
61 lines (48 loc) · 2.06 KB
/
CellColorHelper.vb
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
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Namespace WindowsApplication1
Public Class CellColorHelper
Private colors As Dictionary(Of MyGridCell, Color) = New Dictionary(Of MyGridCell, Color)()
Private ReadOnly _View As GridView
''' <summary>
''' Initializes a new instance of the CellColorHelper class.
''' </summary>
Public Sub New(ByVal view As GridView)
_View = view
AddHandler _View.RowCellStyle, AddressOf _View_RowCellStyle
End Sub
Private Sub _View_RowCellStyle(ByVal sender As Object, ByVal e As RowCellStyleEventArgs)
Dim color As Color = GetCellColor(New MyGridCell(e.RowHandle, e.Column))
If color.IsEmpty Then Return
e.Appearance.BackColor = color
End Sub
Public Function GetCellColor(ByVal cell As MyGridCell) As Color
Dim c As Color = Color.Empty
If colors.TryGetValue(cell, c) Then Return c
Return Color.Empty
End Function
Public Sub SetCellColor(ByVal rowHandle As Integer, ByVal column As GridColumn, ByVal value As Color)
SetCellColor(New MyGridCell(rowHandle, column), value)
End Sub
Public Sub SetCellColor(ByVal cell As MyGridCell, ByVal value As Color)
colors(cell) = value
_View.RefreshRowCell(cell.RowHandle, cell.Column)
End Sub
End Class
Public Class MyGridCell
Inherits GridCell
Public Sub New(ByVal rowHandle As Integer, ByVal column As GridColumn)
MyBase.New(rowHandle, column)
End Sub
Public Overrides Function GetHashCode() As Integer
Return Column.GetHashCode() + RowHandle.GetHashCode()
End Function
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Return Equals(TryCast(obj, GridCell))
End Function
End Class
End Namespace