Hi,
Vince P said:
How could I format the background of a DataGridView cell with a gradiant
brush?
Depends on which cells you want to fill with gradient brush. Have a look at
:
DataGridView.RowPrePaint and / or
DataGridView.CellPainting
The following code applies a gradient background to each cell within the
first column that isn't selected:
dataGridView1.CellPainting +=
new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if ((e.ColumnIndex==0) && (e.RowIndex != -1) &&
(e.State & DataGridViewElementStates.Selected)!=
DataGridViewElementStates.Selected)
{
// fill gradient background
Brush gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
e.CellBounds, Color.Blue, Color.BlueViolet,
System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(gradientBrush, e.CellBounds);
backbrush.Dispose();
// paint rest of cell
e.Paint(e.CellBounds, DataGridViewPaintParts.Border |
DataGridViewPaintParts.ContentForeground);
e.Handled = true;
}
}
HTH,
Greetings