Gets the sorting information.
Syntax
Visual Basic (Declaration) | |
---|
Public ReadOnly Property SortInfo As SortInfo |
Property Value
SortInfo object containing the sorting information
Example
This example sets a custom comparer for the grouped items.
C# | Copy Code |
---|
<Serializable()>
public class MyGroupComparer1 : System.Collections.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.ActiveSheetView.AllowColumnMove = true;
FpSpread1.ActiveSheetView.AllowGroup = true;
FpSpread1.ActiveSheetView.GroupBarVisible = true;
FarPoint.Web.Spread.GroupInfo gi = new FarPoint.Web.Spread.GroupInfo();
FpSpread1.ActiveSheetView.GroupInfos.Add(gi);
void FpSpread1_Grouping(object sender, GroupingEventArgs e)
{
int c = e.SortInfo.Index;
FarPoint.Web.Spread.FpSpread ss = (FarPoint.Web.Spread.FpSpread)sender;
FarPoint.Web.Spread.Model.DefaultSheetDataModel dm;
if ((ss.ActiveSheetView.DataModel) is FarPoint.Web.Spread.Model.DefaultSheetDataModel)
{
dm = (FarPoint.Web.Spread.Model.DefaultSheetDataModel)ss.ActiveSheetView.DataModel;
}
else
{
dm = (FarPoint.Web.Spread.Model.DefaultSheetDataModel)((FarPoint.Web.Spread.Model.GroupDataModel)ss.ActiveSheetView.DataModel).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);
}
}
}
|
Visual Basic | Copy Code |
---|
FpSpread1.ActiveSheetView.AllowColumnMove = True
FpSpread1.ActiveSheetView.GroupBarVisible = True
FpSpread1.ActiveSheetView.AllowGroup = True
Dim gi As New FarPoint.Web.Spread.GroupInfo
gi.BackColor = Color.Yellow
Dim gi2 As New FarPoint.Web.Spread.GroupInfo
gi2.BackColor = Color.Green
Dim gic As New FarPoint.Web.Spread.GroupInfoCollection()
gic.Add(gi)
FpSpread1.ActiveSheetView.GroupInfos.Add(gic(0))
<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_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
End Class
|
Requirements
Target Platforms: Windows 7, Windows 8, Windows Vista, Windows Server 2000, Windows 2000 Professional, Windows XP Professional, Windows NT 4.0 Workstation, SP6, Windows NT 4.0 Server, SP6
See Also