You can handle the CellPainting event to draw the style you want, something like this
Code Block
void Form4_Load(object sender, EventArgs e)
{
this.dataGridView1.Columns.Add("c1", "c1");
this.dataGridView1.Columns.Add("c2", "c2");
this.dataGridView1.Columns.Add("c3", "c3");
this.dataGridView1.Rows.Add("Hello\nWorld", "bbb", "ccc");
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[0].Height = this.dataGridView1.RowTemplate.Height * 2;
this.dataGridView1.CellPainting +=
new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
}
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == 0 && e.ColumnIndex > -1)
{
e.Handled = true;
e.PaintBackground(e.CellBounds,true);
if (e.ColumnIndex != 0)
{
e.PaintContent(e.CellBounds);
}
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawLine(pen, e.CellBounds.Left, e.CellBounds.Bottom - 1,
e.CellBounds.Right, e.CellBounds.Bottom - 1);
}
if (e.ColumnIndex == 0)
{
Rectangle rect = e.CellBounds;
rect.Height /= 2;
using (Font f = new Font(e.CellStyle.Font, FontStyle.Underline))
using (SolidBrush br = new SolidBrush(e.CellStyle.ForeColor))
{
e.Graphics.DrawString("Hello", f, br, rect);
rect.Y += rect.Height;
e.Graphics.DrawString("World", e.CellStyle.Font, br, rect);
}
}
}
}
You can use google to search for other answers
|