0
votes

I have a DevExpress GridView whose cells are painted with a random color based on some condition. Now each color has a meaning and I want to show it as a legend. Number of colors used for each condition may vary.

How can I do this. Please help.

I'm using DevExpress 2009 Vol2, and .Net framework - 2.0 and WinForms

1
I don't believe that's possible unless you look into "custom paint" of the control. I believe a more simple solution would be to create an image graphic of our legend and put it at the side(s) or bottom of your grid. - Saif Khan

1 Answers

1
votes

You might try using another GridControl. DataSource would be this simple class:

class Legend
{
    public Legend(string caption, Color color)
    {
        Caption = caption;
        Color = color;
    }

    public string Caption { get; set; }
    public Color Color { get; set; }
}

You would populate it while building your color list; I don't know your setup so, for example,

gridControl1.DataSource = new List<Legend> 
{
    new Legend ( "First", Color.AliceBlue), 
    new Legend ( "Second", Color.Azure), 
    new Legend ( "Third", Color.Bisque) 
};

GridControl would have two columns, first one for Color and second for Caption. You must set ColumnEdit property of first column to ColorEdit. In order to avoid color name being displayed set AppearanceCell's ForeColor property to transparent. Also set FixedWidth in OptionsColumn to true and Width to some nice number (32 for my system).

View should be uneditable (OptionsBehavior.Editable = false) and focus should not use it's own appearance (OptionsSelection.EnableAppearanceFocusedRow = false). Additionally, you might hide header, hide row indicators, disallow GridControl from receiving focus etc.

I hope this helps, even if it arrives two weeks late.