Hello all:
I wanted to remove the padding on my datagridview cell and used some code I found here on this forum..
this.dataGridView1.CellPainting += new
DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)//remove padding
{
// ignore the column header and row header cells
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
e.PaintBackground(e.ClipBounds, true);
e.Graphics.DrawString(Convert.ToString(e.FormattedValue), e.CellStyle.Font, Brushes.Gray, e.CellBounds.X, e.CellBounds.Y - 2, StringFormat.GenericDefault)
e.Handled = true;
}
}
It works great, all the padding is gone but theres a problem now with the styling of the cell, my color delclarations are now overridden as the Method uses
Brushes.Gray
and I loose my styling work...
DataGridViewCellStyle currenyCellStyle = new DataGridViewCellStyle();
currenyCellStyle.Format = "C";
currenyCellStyle.ForeColor = Color.Green;
this.dataGridView1.Columns[2].DefaultCellStyle = currenyCellStyle;
The cell ForeColor is Gray and not Green
Is there any way i can get round this, any help appreciated
Regards
Tino