Home Forums WinForms controls Xceed Grid for WinForms different cell colors in the selected row

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17265 |

    Hello,

    We are currently setting the background color of particular cells in the Xceed grid depending on the data values in the cell.  So, for example, if a certain flag is set for the row, we color the Total Price cell’s background red.  The problem is that when we select a row with a cell that has a special color, the selected row color overwrites that cell’s color.  If we choose a different row to select, the cell is colored correctly again now that it is unselected.  Is there any way to get the special color to “show through” the selected row background color?

    Thanks!

    Imported from legacy forums. Posted by Rachel (had 1724 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Rachel,

    This behavior is normal, and is caused by the order in which the different layers are painted. The selection color is painted after the cell’s background, and will therefore ‘override’ it.

    There’s two options that we can suggest. You can either make your selection color be transparent, so that if a cell has a background color it will be able to show through. Note however that the color will ‘merge’ with the selection color (if the cell’s background is red and your selection color is a light blue, the cell will appear as a red leaning slightly on purple).

    The other option is to remove completely the selection color and instead use only the focus rectangle as your indicator of which row is currently selected.

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 404 views)

    User (Old forums)
    Member
    Post count: 23064

    You can set the grid.SelectionBackColor to a color you want, with an alpha value to make it opaque.

    I too am setting certain cell background colors.  The opaque selection allows most of the background color to come through.

    I’m using a stylesheet I got from the Validation sample, and modified it to this:

    styleSheet.Grid.SelectionBackColor = Color.FromArgb(40, Color.Cyan);
    styleSheet.Grid.SelectionForeColor = Color.FromArgb(29, 50, 139);

    I also subclassed the GridControl and overrided PaintFocusRectangle, to draw a more prominent border around a selected cell.  I’m not sure I like the look yet, but it’s a start.  Hope this helps.

            protected override void PaintFocusRectangle(VisualGridElement gridElement, Graphics graphics, Rectangle displayRectangle, Color backColor, Color foreColor, bool printing)
            {

                // Draw a black border around the cell.
                Rectangle borderRectangle = new Rectangle(displayRectangle.X, displayRectangle.Y, displayRectangle.Width – 1, displayRectangle.Height – 1);
                graphics.DrawRectangle(Pens.Black, borderRectangle);
            }

    Imported from legacy forums. Posted by Buzz (had 1268 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.