FarPoint.Win.Spread Assembly > FarPoint.Win.Spread Namespace > GroupingEventArgs Class : GroupComparer Property |
'Declaration Public Property GroupComparer As IComparer
'Usage Dim instance As GroupingEventArgs Dim value As IComparer instance.GroupComparer = value value = instance.GroupComparer
public IComparer GroupComparer {get; set;}
[Serializable()] public class MyGroupComparer1 : IComparer { private bool birthDate = true; public MyGroupComparer1(bool bd) { birthDate = bd; } public int Compare(object x1, object y1) { int x; int y; x = 0; y = 0; if (birthDate) { if ((x1) is DateTime) { x = ((DateTime)(x1)).Year % 10; x = ((DateTime)(x1)).Year - x; } if ((y1) is DateTime) { y = ((DateTime)(y1)).Year % 10; y = ((DateTime)(y1)).Year - y; } } else { if ((x1) is DateTime) { x = ((DateTime)(x1)).Year; } if ((y1) is DateTime) { y = ((DateTime)(y1)).Year; } } if (x == y) { return 0; } else if (x > y) { return 1; } else { return -1; } } } fpSpread1.AllowColumnMove = true; fpSpread1.ActiveSheet.GroupBarInfo.Visible = true; fpSpread1.ActiveSheet.AllowGroup = true FarPoint.Win.Spread.GroupInfo gi = new FarPoint.Win.Spread.GroupInfo(); gi.BackColor = Color.Yellow FarPoint.Win.Spread.GroupInfo gi2 = new FarPoint.Win.Spread.GroupInfo(); gi2.BackColor = Color.Green FarPoint.Win.Spread.GroupInfoCollection gic = new FarPoint.Win.Spread.GroupInfoCollection(); gic.AddRange(new FarPoint.Win.Spread.GroupInfo[] { gi, gi2 }); fpSpread1.ActiveSheet.GroupInfos.Add(gic[0]); void fpSpread1Grouping(object sender, GroupingEventArgs e) { int n = e.SortInfo.Length; if ((n == 0)) { e.Cancel = true; } int c = e.SortInfo[n - 1].Index; FarPoint.Win.Spread.FpSpread ss = (FarPoint.Win.Spread.FpSpread)sender; FarPoint.Win.Spread.Model.DefaultSheetDataModel dm; if ((ss.ActiveSheet.Models.Data) is FarPoint.Win.Spread.Model.DefaultSheetDataModel) { dm = (FarPoint.Win.Spread.Model.DefaultSheetDataModel)ss.ActiveSheet.Models.Data; } else { dm = (FarPoint.Win.Spread.Model.DefaultSheetDataModel)((FarPoint.Win.Spread.Model.GroupDataModel)ss.ActiveSheet.Models.Data).TargetModel; } c = dm.GetDataColumnFromModelColumn(c); if (dm.GetDataView().Table.Columns[c].DataType.Equals(typeof(DateTime))) { if ((dm.GetDataView().Table.Columns[c].Caption.IndexOf("Birth") >= 0)) { e.GroupComparer = new MyGroupComparer1(true); } else { e.GroupComparer = new MyGroupComparer1(false); } } }
[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 FpSpread1.AllowColumnMove = True FpSpread1.ActiveSheet.GroupBarInfo.Visible = True FpSpread1.ActiveSheet.AllowGroup = True Dim gi As New FarPoint.Win.Spread.GroupInfo gi.BackColor = Color.Yellow Dim gi2 As New FarPoint.Win.Spread.GroupInfo gi2.BackColor = Color.Green Dim gic As New FarPoint.Win.Spread.GroupInfoCollection() gic.AddRange(New FarPoint.Win.Spread.GroupInfo() {gi, gi2}) FpSpread1.ActiveSheet.GroupInfos.Add(gic.Item(0)) Private Sub FpSpread1Grouping(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.GroupingEventArgs) Handles FpSpread1.Grouping Dim n As Integer = e.SortInfo.Length If n = 0 Then e.Cancel = True End If Dim c As Integer = e.SortInfo(n - 1).Index 'model index Dim ss As FarPoint.Win.Spread.FpSpread = sender Dim dm As FarPoint.Win.Spread.Model.DefaultSheetDataModel If TypeOf (ss.ActiveSheet.Models.Data) Is FarPoint.Win.Spread.Model.DefaultSheetDataModel Then dm = ss.ActiveSheet.Models.Data Else dm = CType(ss.ActiveSheet.Models.Data, FarPoint.Win.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
Target Platforms: Windows 2000 Professional (SP4), Windows 2000 Server, Windows 2003 Server (SP1), Windows 2008, Windows XP (SP2), Windows Vista, Windows 7, Windows 8