Sort grid by color

2 posts, 0 answers
  1. Vladimir
    Vladimir avatar
    1 posts
    Member since:
    Nov 2013

    Posted 27 Nov 2013 Link to this post

    Hello,
              I have a GridView with some rows colored and some not. I would like to display the color rows on top and the none color rows on the bottom. Is there a way I can Sort by color?
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 02 Dec 2013 Link to this post

    Hello Vladimir,

    Thank you for contacting Telerik Support.

    It is possible to sort the RadGridView by Color property. It is necessary to use Color.Empty value for none color cells. Thus when sorting (ascending), the empty value is on the bottom:
    public Form1()
    {
        InitializeComponent();
     
        List<Color> colors = new List<Color>()
        {
            Color.Red, Color.Empty, Color.Yellow, Color.Green,
            Color.Black, Color.Empty, Color.Fuchsia, Color.Pink,
            Color.Gray, Color.Blue
        };
        List<ColorItem> list = new List<ColorItem>();
        for (int i = 0; i < 10; i++)
        {
            list.Add(new ColorItem(i,colors[i],colors[i].ToString()));
        }
        radGridView1.DataSource = list;
        radGridView1.EnableSorting = true;
    }
     
    public class ColorItem
    {
        public int ID { get; set; }
     
        public Color Color { get; set; }
     
        public string Description { get; set; }
     
        public ColorItem(int iD, Color color, string description)
        {
            this.ID = iD;
            this.Color = color;
            this.Description = description;
        }
    }

    If it is necessary to use some custom logic when sorting, you may use Custom Sorting. More information about it can be found in the referred help article.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top