Hvala i u moje ime. Biću slobodan da ostavim deo koda koji je bitan za rešavanje ovog problema.
Kôd:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if ((e.ColumnIndex == 1) && (e.RowIndex >= 0))
{
// Draw Merged Cell
Graphics g = e.Graphics;
bool selected = ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected);
Color fcolor = (selected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor);
Color bcolor = (selected ? e.CellStyle.SelectionBackColor : e.CellStyle.BackColor);
Font font = e.CellStyle.Font;
if (!(this.messageBS[e.RowIndex] as MailMessage).Read)
{
font = new Font(font, FontStyle.Bold);
}
// Get size information
string from = (this.messageBS[e.RowIndex] as MailMessage).From;
string subject = (this.messageBS[e.RowIndex] as MailMessage).Subject;
Size size = TextRenderer.MeasureText(e.Graphics, from, font);
// Note that this always aligns top, right
// Also this should use the ClipBounds but that is not currently working
int x = e.CellBounds.Left + e.CellStyle.Padding.Left;
int y = e.CellBounds.Top + e.CellStyle.Padding.Top;
int width = e.CellBounds.Width - (e.CellStyle.Padding.Left + e.CellStyle.Padding.Right);
int height = size.Height + (e.CellStyle.Padding.Top + e.CellStyle.Padding.Bottom);
// Draw background
g.FillRectangle(new SolidBrush(bcolor), e.CellBounds);
// Draw first line
TextRenderer.DrawText(e.Graphics, from, font, new Rectangle(x, y, width, height), fcolor, TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.EndEllipsis);
// Use grey for second line if not selected
if (!selected)
{
fcolor = Color.Gray;
}
// Reset font and y location
font = e.CellStyle.Font;
y = y + height - 1;
TextRenderer.DrawText(e.Graphics, subject, font, new Rectangle(x, y, width, height), fcolor, TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.EndEllipsis);
// Let them know we handled it
e.Handled = true;
}
else if ((e.ColumnIndex == 0) && (e.RowIndex >= 0))
{
e.Paint(e.ClipBounds, e.PaintParts & ~DataGridViewPaintParts.Focus);
e.Handled = true;
}
}