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);<br/>
<br/>
void
dataGridView1_CellPainting(object
sender, DataGridViewCellPaintingEventArgs e)//remove padding<br/>
{<br/>
// ignore the column header and row header cells<br/>
if
(e.RowIndex != -1 && e.ColumnIndex != -1)<br/>
{<br/>
e.PaintBackground(e.ClipBounds, true
);<br/>
e.Graphics.DrawString(Convert.ToString(e.FormattedValue), e.CellStyle.Font, <strong>Brushes.Gray</strong>
, e.CellBounds.X, e.CellBounds.Y - 2, StringFormat.GenericDefault);<br/>
e.Handled = true
;<br/>
}<br/>
}
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
and I loose my styling work...
DataGridViewCellStyle currenyCellStyle = new
DataGridViewCellStyle();<br/>
currenyCellStyle.Format = "C"
;<br/>
currenyCellStyle.ForeColor = Color.Green;<br/>
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