Нужно переопределить метод Paint для ячейки. Так работает. Хорошо работает, только если ячейка ReadOnly, а это как раз мой случай.
public class DataGridViewCustomCell : DataGridViewTextBoxCell
{
protected override void Paint(
Graphics graphics,
Rectangle clipBounds,
Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates cellState,
Object value,
Object formattedValue,
string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts
)
{
// base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
SolidBrush myBrush = new SolidBrush(Color.White);
graphics.FillRectangle(myBrush, cellBounds);
Pen myPen = new Pen(Color.Gray, 1); //+ cellBounds.Height
graphics.DrawLine(myPen, cellBounds.X, cellBounds.Y + cellBounds.Height- 1,
cellBounds.X + cellBounds.Width, cellBounds.Y + cellBounds.Height -1);
myBrush.Dispose();
if (this.FormattedValue is String)
{
TextRenderer.DrawText(graphics,
(string)this.FormattedValue,
this.DataGridView.Font,
cellBounds, SystemColors.GrayText);
}
}
}