This is a migrated thread and some comments may be shown as answers.

Sort grid by color

1 Answer 34 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Vladimir asked on 27 Nov 2013, 03:43 PM
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?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Dec 2013, 11:23 AM
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 >>
Tags
GridView
Asked by
Vladimir
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or