Private Function GetYear(ByVal value As DateTime) As Integer
Return value.Year
End Function
Private Function GetDecade(ByVal value As DateTime) As Integer
Dim x As Integer = 0
x = value.Year Mod 10
x = value.Year - x
Return x
End Function
<Serializable()> _
Public Class MyGroupComparer
Implements IComparer
Private birthDate As Boolean = True
Public Sub New(ByVal bd As Boolean)
birthDate = bd
End Sub
Public Function Compare(ByVal x1 As Object, ByVal y1 As Object) As Integer Implements System.Collections.IComparer.Compare
Dim x, y As Integer
x = 0
y = 0
If birthDate Then
If TypeOf (x1) Is DateTime Then
x = CType(x1, DateTime).Year Mod 10
x = CType(x1, DateTime).Year - x
End If
If TypeOf (y1) Is DateTime Then
y = CType(y1, DateTime).Year Mod 10
y = CType(y1, DateTime).Year - y
End If
Else
If TypeOf (x1) Is DateTime Then
x = CType(x1, DateTime).Year
End If
If TypeOf (y1) Is DateTime Then
y = CType(y1, DateTime).Year
End If
End If
If x = y Then
Return 0
ElseIf x > y Then
Return 1
Else
Return -1
End If
End Function
End Class
Protected Sub FpSpread1_Grouped(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.Grouped
Dim ss As FarPoint.Web.Spread.FpSpread = sender
Dim gm As FarPoint.Web.Spread.Model.GroupDataModel
If TypeOf (ss.ActiveSheetView.DataModel) Is FarPoint.Web.Spread.Model.GroupDataModel Then
gm = ss.ActiveSheetView.DataModel
If TypeOf (gm.GroupComparer) Is MyGroupComparer Then
Dim i As Integer
For i = 0 To ss.ActiveSheetView.RowCount - 1
If gm.IsGroup(i) Then
Dim g As FarPoint.Web.Spread.Model.Group
g = gm.GetGroup(i)
If TypeOf (g.Rows(0)) Is Integer And Not gm.IsEditable(i, g.Column) Is Integer Then
Dim s As String = ss.ActiveSheetView.GetColumnLabel(0, ss.ActiveSheetView.GetViewColumnFromModelColumn(g.Column))
If s.IndexOf("Birth") >= 0 Then
g.Text = s & ": " & GetDecade(gm.TargetModel.GetValue(g.Rows(0), g.Column)) & "s"
Else
g.Text = s & ": " & GetYear(gm.TargetModel.GetValue(g.Rows(0), g.Column))
End If
End If
End If
Next
End If
End If
End Sub
Protected Sub FpSpread1_Grouping(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.GroupingEventArgs) Handles FpSpread1.Grouping
Dim c As Integer = e.SortInfo.Index
Dim ss As FarPoint.Web.Spread.FpSpread = sender
Dim dm As FarPoint.Web.Spread.Model.DefaultSheetDataModel
If TypeOf (ss.ActiveSheetView.DataModel) Is FarPoint.Web.Spread.Model.DefaultSheetDataModel Then
dm = ss.ActiveSheetView.DataModel
Else
dm = CType(ss.ActiveSheetView.DataModel, FarPoint.Web.Spread.Model.GroupDataModel).TargetModel
End If
c = dm.GetDataColumnFromModelColumn(c)
If dm.GetDataView().Table.Columns(c).DataType.Equals(GetType(DateTime)) Then
If dm.GetDataView().Table.Columns(c).Caption.IndexOf("Birth") >= 0 Then
e.GroupComparer = New MyGroupComparer(True)
Else
e.GroupComparer = New MyGroupComparer(False)
End If
End If
End Sub