Change sort indicator (icon) for sortable header

Sep 10, 2009 at 3:18 PM

Hi. I'd like to know if it is possible to change the sort indicator (icon representing the ascending/descending sort style) for a sortable header. Thanks.

Coordinator
Sep 11, 2009 at 6:48 AM

Yes, it is.


There should be a property for the sort indicator images.

P.s. it might be the case that the property does not exist. In that file a new feature request, or send a patch (which i will gladly apply)

Sep 11, 2009 at 10:06 AM

Hi.

After a good look through the SourceGrid code this is what I came up with...

After declaring the column header

SourceGrid.Cells.ColumnHeader _ColHeader = new SourceGrid.Cells.ColumnHeader ( "ColumnName" );
_ColHeader.View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
you can define the ElementSort for the column header's View
( ( SourceGrid.Cells.Views.ColumnHeader ) _ColHeader.View ).ElementSort = new MySortIndicator ( );
the magic is done with the MySortIndicator class
using System;
using DevAge.Drawing;
using DevAge.Drawing.VisualElements;

namespace MyApp
{
    class MySortIndicator : SortIndicator
    {
        public override HeaderSortStyle SortStyle
        {
            get { return base.SortStyle; }
            set
            {
                base.SortStyle = value;
                if ( base.SortStyle == HeaderSortStyle.Ascending )
                {
                    Value = System.Drawing.Icon.FromHandle ( MyApp.Resources.Resources.SortAscending.GetHicon ( ) );
                }
                else if ( base.SortStyle == HeaderSortStyle.Descending )
                {
                    Value = System.Drawing.Icon.FromHandle ( MyApp.Resources.Resources.SortDescending.GetHicon ( ) );
                }
                else
                {
                    Value = null;
                }
            }
        }
    }
}

I'm creating the Icons (the Value property) from a handle because I'm using PNGs as my image sources.

I hope this helps.