How to make DataGridViewLinkColumn underline and change background color?

Niladri.Biswas
Posted by Niladri.Biswas under Windows Forms category on | Points: 40 | Views : 11062
I have a DataGridViewLinkColumn.How can I make the header(row = -1) as underline and change it's background color?

Solution

private void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex == 2)
{
e.Handled = true;
e.Graphics.FillRectangle(Brushes.cont, e.CellBounds);
StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
Font f = new Font(e.CellStyle.Font, FontStyle.Underline);
e.Graphics.DrawString(e.Value.ToString(), f, new SolidBrush(e.CellStyle.ForeColor), e.CellBounds, sf);
}
}

Comments or Responses

Login to post response