You can customize the display of sorting indicators in these ways:
- Using Custom Sort Indicator Images
- Showing and Hiding Sort Indicators
- Determining Which Header Row Displays the Sort Indicators
Return to the overview at Managing Sorting of Rows of User Data.
Using Custom Sort Indicator Images
You can customize the sorting indicator image that appears in the column header of columns that allow sorting. One of the default sort indicators is shown in the header of the first (A) column.
One way is to override the PaintSortIndicator method in the CellType ColumnHeaderRenderer class and use your own custom indicator.
Another way is to use the GetImage and SetImage methods in the SpreadView class, which is described in Customizing the User Interface Images.
Showing and Hiding Sort Indicators
You can display for the user or hide from the user the sort indicators that may appear in the column headers. The Column.ShowSortIndicator property and the SheetView.SetColumnShowSortIndicator method set whether the column shows the sort indicator the next time that the SheetView.AutoSortColumns method is called for that column. It has no effect until AutoSortColumns is called for that column index.
Determining Which Header Row Displays the Sort Indicators
You can specify in which row to display the sort indicators that may appear in the column headers. By default they appear in the bottom of the column header rows, but if you have more than one header row, you can specify which row. You can specify which row displays the automatic text by setting the ColumnHeaderAutoTextIndex property (or the ColumnHeader.AutoTextIndex Property).
Using Code
Here is an example of how to set create a custom sort indicator in code.
- Create a new column header renderer class.
- Customize the sort indicator that appears in the column header.
Example
C# | Copy Code |
---|---|
// In the form load section, allow sorting (and filtering). private void Form1_Load(object sender, System.EventArgs e) { fpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = new myColumnHeaderRenderer(); fpSpread1.Sheets[0].Columns[0].AllowAutoSort =true; fpSpread1.Sheets[0].Columns[0].AllowAutoFilter =true; } // Define a new column header renderer. public class myColumnHeaderRenderer : FarPoint.Win.Spread.CellType.ColumnHeaderRenderer { // Override the sorting indicator paint method. override public void PaintSortIndicator(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, float zoomFactor) { g.FillRectangle(new SolidBrush(Color.Red), r); } // Override the filtering indicator paint method. override public void PaintFilterIndicator(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, float zoomFactor) { g.FillRectangle(new SolidBrush(Color.Blue), r); } } //End Form1_Load |
VB | Copy Code |
---|---|
' Define a new column header renderer. Public Class myColumnHeaderRenderer Inherits FarPoint.Win.Spread.CellType.ColumnHeaderRenderer ' Override the sorting indicator paint method. Public Overrides Sub PaintSortIndicator(ByVal g As Graphics, ByVal r As Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) g.FillRectangle(New SolidBrush(Color.Red), r) End Sub 'PaintSortIndicator ' Override the filtering indicator paint method. Public Overrides Sub PaintFilterIndicator(ByVal g As Graphics, ByVal r As Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) g.FillRectangle(New SolidBrush(Color.Blue), r) End Sub 'PaintFilterIndicator End Class 'myColumnHeaderRenderer ' In the form load section, allow sorting (and filtering). Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load FpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = New myColumnHeaderRenderer FpSpread1.Sheets(0).Columns(0).AllowAutoSort = True FpSpread1.Sheets(0).Columns(0).AllowAutoFilter = True End Sub 'Form1_Load |