Reputation: 2620
I've tried alter ForeColor of all rows of my DataGridView using this code:
private void dgv_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
if (e.RowIndex >= 0) {
DataGridViewRow row = dgv.Rows[e.RowIndex];
e.CellStyle.ForeColor = Color.Green;
}
}
But the first line doesn't receive update.
Has anybody else had this problems?
Thanks a lot.
Upvotes: 0
Views: 91
Reputation: 2620
The problem was: the first line was select. To fix just clear the selection of rows after update the ForeColor.
private void dgv_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
if (e.RowIndex >= 0) {
DataGridViewRow row = dgv.Rows[e.RowIndex];
e.CellStyle.ForeColor = Color.Green;
}
dgv.ClearSelection();
}
Upvotes: 0
Reputation:
Use CellFormatting
event
simply try this:
private void dgv_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
e.CellStyle.ForeColor = Color.Green;
}
see this picture.
Upvotes: 2