/
RowVisibilityHelper.vb
86 lines (75 loc) · 2.25 KB
/
RowVisibilityHelper.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
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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid
Imports System.Collections
Namespace WindowsApplication1
Public Class RowVisibilityHelper
Inherits Component
Private _GridView As GridView
Public Property GridView() As GridView
Get
Return _GridView
End Get
Set(ByVal value As GridView)
UnSubscribeEvents()
_GridView = value
SubscribeEvents()
End Set
End Property
Private _InvisibleRows As List(Of Integer)
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property InvisibleRows() As List(Of Integer)
Get
If _InvisibleRows Is Nothing Then
_InvisibleRows = New List(Of Integer)()
End If
Return _InvisibleRows
End Get
Set(ByVal value As List(Of Integer))
_InvisibleRows = value
End Set
End Property
Private Sub UnSubscribeEvents()
If GridView IsNot Nothing Then
RemoveHandler GridView.CustomRowFilter, AddressOf GridView_CustomRowFilter
End If
End Sub
Private Sub SubscribeEvents()
AddHandler GridView.CustomRowFilter, AddressOf GridView_CustomRowFilter
End Sub
Public Function IsRowInvisible(ByVal dataSourceRowIndex As Integer) As Boolean
Return InvisibleRows.Contains(dataSourceRowIndex)
End Function
Private Sub GridView_CustomRowFilter(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowFilterEventArgs)
If IsRowInvisible(e.ListSourceRow) Then
e.Visible = False
e.Handled = True
End If
End Sub
Public Sub HideRow(ByVal dataSourceRowIndex As Integer)
If (Not IsRowInvisible(dataSourceRowIndex)) Then
InvisibleRows.Add(dataSourceRowIndex)
End If
GridView.RefreshData()
End Sub
Public Sub ShowRow(ByVal dataSourceRowIndex As Integer)
If IsRowInvisible(dataSourceRowIndex) Then
InvisibleRows.Remove(dataSourceRowIndex)
End If
GridView.RefreshData()
End Sub
Public Sub ToggleRowVisibility(ByVal dataSourceRowIndex As Integer)
If IsRowInvisible(dataSourceRowIndex) Then
ShowRow(dataSourceRowIndex)
Else
HideRow(dataSourceRowIndex)
End If
End Sub
End Class
End Namespace