A Problem About DataGridViewNumericUpDown.Can U Handle it?

DataGridViewNumericUpDown is a useful! A problem is occured when i used it :

When I got then DataGridViewNumbericUpDown Cell , It's foreColor still is Black .I can not see it ! Help me pls !




Answer this question

A Problem About DataGridViewNumericUpDown.Can U Handle it?

  • harlequinben

    Hi,

    I have found a solution for this. Please look at the code below. You will notice the use of foreColor in addition to backColor. This needed to be set according to the cellStyle.

    The code is at or around line 588 in DataGridViewNumericUpDownCell.cs.

    Color backColor;
    Color foreColor;
    if (PartPainted(paintParts, DataGridViewPaintParts.SelectionBackground) && cellSelected)
    {
    backColor = cellStyle.SelectionBackColor;
    foreColor = cellStyle.SelectionForeColor;
    }
    else
    {
    backColor = cellStyle.BackColor;
    foreColor = cellStyle.ForeColor;
    }
    if (PartPainted(paintParts, DataGridViewPaintParts.Background))
    {
    if (backColor.A < 255)
    {
    // The NumericUpDown control does not support transparent back colors
    backColor = Color.FromArgb(255, backColor);
    }
    paintingNumericUpDown.BackColor = backColor;
    paintingNumericUpDown.ForeColor = foreColor;
    }
    // Finally paint the NumericUpDown control

    I hope this helps.

    Luc


  • Paul Stovell

    The Paint method seems like it’s not working well. Just remove it and the cell will use the method in the base class. Of course, when not editing, the cell looks like a textbox cell, but the text can now be readed.


  • A Problem About DataGridViewNumericUpDown.Can U Handle it?