-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyGridViewInfo.vb
118 lines (116 loc) · 5.48 KB
/
MyGridViewInfo.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
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
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraGrid.Drawing
Imports DevExpress.XtraGrid
Imports System.Collections
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.Data
Namespace Q354185.MyXtraGrid
Public Class MyGridViewInfo
Inherits GridViewInfo
Public Sub New(ByVal gridView As GridView)
MyBase.New(gridView)
End Sub
Protected Overrides Function CalcGroupFooterHeight() As Integer
Dim myView = CType(View, MyGridView)
If myView.GetGroupFooterRowCount() <= 0 Then
Return 0
End If
Return MyBase.CalcGroupFooterHeight() * myView.GetGroupFooterRowCount()
End Function
'protected override int GetMaxColumnFooterCount() {
' return ((MyGridView)View).GetGroupFooterRowCount();
'}
Protected Overrides Sub CalcRowCellsFooterInfo(ByVal fi As GridRowFooterInfo, ByVal ri As GridRowInfo)
AddColumnsInfo(fi.RowHandle)
MyBase.CalcRowCellsFooterInfo(fi, ri)
ChangeDisplayText(fi)
RemoveColumnsInfo()
End Sub
Private Sub AddColumnsInfo(ByVal rowHandle As Integer)
rowHandle = If(rowHandle >= 0, -1, rowHandle)
Dim groupSummary = View.GetGroupSummaryValues(rowHandle)
Dim myGroupSummaryList = New List(Of DictionaryEntry)()
For Each item As DictionaryEntry In groupSummary
myGroupSummaryList.Add(item)
Next item
Dim query = From item In myGroupSummaryList _
Let summary = CType(item.Key, GridGroupSummaryItem) _
Group item By summary.ShowInGroupColumnFooter Into Group
For Each group In query
For i = 1 To group.Group.Count - 1
Dim sourceCInfo = ColumnsInfo(group.ShowInGroupColumnFooter)
If sourceCInfo Is Nothing Then
Continue For
End If
Dim cellInfo = New GridColumnInfoArgs(sourceCInfo.Column)
cellInfo.Assign(sourceCInfo)
cellInfo.Tag = TryCast(group.Group(i).Key, GridGroupSummaryItem)
cellInfo.Info.StartRow = i
ColumnsInfo.Add(cellInfo)
Next i
Next group
End Sub
Private Sub AddNewColumnsInfo(ByVal group As List(Of DictionaryEntry), ByVal i As Integer, ByVal initCellInfo As GridColumnInfoArgs)
Dim cellInfo = New GridColumnInfoArgs(initCellInfo.Column)
cellInfo.Assign(initCellInfo)
cellInfo.Tag = TryCast(group(i).Key, GridGroupSummaryItem)
cellInfo.Info.StartRow = i
ColumnsInfo.Add(cellInfo)
End Sub
Private Sub RemoveColumnsInfo()
Dim count = ColumnsInfo.OfType(Of GridColumnInfoArgs)().Where(Function(ci) ci.Tag Is Nothing).Count()
Do While ColumnsInfo.Count > count
ColumnsInfo.RemoveAt(count)
Loop
End Sub
Private Sub ChangeDisplayText(ByVal fi As GridRowFooterInfo)
For Each fci As GridFooterCellInfoArgs In fi.Cells
Dim rowSummaryItem = View.GetRowSummaryItem(fi.RowHandle, fci.Column)
If rowSummaryItem.Key Is Nothing Then
Continue For
End If
Dim item = TryCast(fci.ColumnInfo.Tag, GridGroupSummaryItem)
If item Is Nothing Then
fci.Visible = If(CType(rowSummaryItem.Key, GridGroupSummaryItem).SummaryType = SummaryItemType.None, False, True)
Continue For
End If
fci.Visible = If(item.SummaryType = SummaryItemType.None, False, True)
ChangeFooterCellDisplayText(fi, fci, item)
Next fci
End Sub
Private Sub ChangeFooterCellDisplayText(ByVal fi As GridRowFooterInfo, ByVal fci As GridFooterCellInfoArgs, ByVal item As GridGroupSummaryItem)
Dim dEntry = GetCustomSummaryItemValue(fi.RowHandle, fci.Column, item)
fci.Visible = If(item.SummaryType = SummaryItemType.None, False, True)
fci.Value = dEntry.Value
fci.DisplayText = DirectCast(dEntry.Key, GridSummaryItem).GetDisplayText(dEntry.Value, False)
End Sub
Public Overridable Function GetCustomSummaryItemValue(ByVal rowHandle As Integer, ByVal column As GridColumn, ByVal summaryItem As Object) As DictionaryEntry
If column Is Nothing Then
Return New DictionaryEntry()
End If
Dim summary = View.GetGroupSummaryValues(rowHandle)
If summary Is Nothing Then
Return New DictionaryEntry()
End If
For Each dEntry As DictionaryEntry In summary
Dim item = TryCast(dEntry.Key, GridGroupSummaryItem)
If item.ShowInGroupColumnFooter IsNot column Then
Continue For
End If
If item IsNot summaryItem Then
Continue For
End If
Return dEntry
Next dEntry
Return New DictionaryEntry()
End Function
Protected Overrides Sub UpdateRowFooterInfo(ByVal ri As GridRowInfo, ByVal fi As GridRowFooterInfo)
MyBase.UpdateRowFooterInfo(ri, fi)
ChangeDisplayText(fi)
End Sub
End Class
End Namespace