Menu

Custom Sort in SourceGrid3

Help
2007-06-14
2013-04-23
  • Nobody/Anonymous

    Hi,

    I need do a custom sort on a column, which display images. Could you please let me know how I do that, and if possible provide me with a sample.

    I am using the SourceGrid3.Grid class.

    Thanks

    Biju Nair

     
    • Nobody/Anonymous

      Hi,

      figured it out myself

      Implemented the IComparer interface like :

      public class ImageComparer : IComparer 
          {

              // Calls CaseInsensitiveComparer.Compare
              int IComparer.Compare( Object x, Object y ) 
              {
                  SourceGrid3.Cells.Real.Image imgX = (SourceGrid3.Cells.Real.Image)x;
                  SourceGrid3.Cells.Real.Image imgY = (SourceGrid3.Cells.Real.Image)y;
             
                  return( (new CaseInsensitiveComparer()).Compare(imgX.Tag.ToString(), imgY.Tag.ToString()) );
              }

          }

      and set the SortComparer for the SourceGrid3.Cells.Real.ColumnHeader object to an instance of the above.

      What I am doing here is using the Tag to store the data to compare for the column with images.

      Useful when you want to display images for boolean columns e.g. show a 'tick' image if true else display a 'cross' image if false.

      Biju Nair

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.