开发者

DataGridViewCellStyle.ForeColor not working as expected

开发者 https://www.devze.com 2023-03-27 23:34 出处:网络
I\'m my WinForms 2.0 application I\'m using a DataGridView and a custom edit control within the current cell (IDataGridViewEditingControl).

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
{
    .开发者_如何学Go..
    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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消