Answers
Aug 22, 2007 - 11:00 PM
Oct 18, 2007 - 03:19 AM
:
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;
}
}
----------------------------------- OR -----------------------------------
private void gridChannel_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
bool isHandled = false;
if (e.RowIndex >= 0 && e.ColumnIndex == 2)
{
if (gridChannel[e.ColumnIndex, e.RowIndex].Value != null &&
IrcBase.MDIParentForm.AppSettings.ProfileWordWatchSettingsCol.CheckForMatch(gri
dChannel[e.ColumnIndex,
e.RowIndex].Value.ToString()))
{
System.Drawing.Drawing2D.LinearGradientBrush lBrush =
new System.Drawing.Drawing2D.LinearGradientBrush(e.CellBounds,
e.CellStyle.BackColor,
IrcBase.MDIParentForm.AppSettings.ProfileMatchCellColor,
System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
e.Graphics.FillRectangle(lBrush, e.CellBounds);
lBrush.Dispose();
e.Paint(e.CellBounds, DataGridViewPaintParts.Border |
DataGridViewPaintParts.ContentBackground |
DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon
| DataGridViewPaintParts.Focus);
e.Handled = true;
isHandled = true;
}
}
if (!isHandled)
{
e.Handled = false;
}
Thanks,
Prash
Mar 24, 2009 - 06:46 AM
The Quomon Team
Add New Comment