DataGridViewCellStyle.ForeColor not working as expected

本秂侑毒 提交于 2020-01-05 08:16:26

问题


I'm my WinForms 2.0 application I'm using a DataGridView and a custom edit control within the current cell (IDataGridViewEditingControl).

The current cell uses my custom edit control that inherits from textbox and implements the IDataGridViewEditingControl interface. This control now registers to the TextChanged event in order to perform some validation logic while the value is edited and to the Leave event to apply some visual effects from the custom edit control to the DataGridView cell.

The code looks somewhat like this:

public class CustomerTextEditingControl : CustomerTextBox, IDataGridViewEditingControl
{
    ...
    protected override void OnLeave(object sender, EventArgs e)
    {
        dataGridView[_col, _row].Style.BackColor = BackgroundColor;
        dataGridView[_col, _row].Style.ForeColor = ForegroundColor;
        ...
    }
    ...
}

Here's my problem now: While the cell's background is properly rendered in whatever color BackgroundColor might be, the text itself is always rendered in black, no matter what color ForegroundColor is. First I thought there might be another Style that applies to the cell's content, but I couldn't find anything there. So I'm puzzled right now :-)

Any help is greatly appreciated!

Thanks Marc


回答1:


Found the problem: the DataGridView class was subclassed and the OnPaintCell method overridden. The only style attribute that was taken account of was BackColor ...



来源:https://stackoverflow.com/questions/7027819/datagridviewcellstyle-forecolor-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!