In the DataGridView of Windows Forms it is possible to change the font color and background color of the selected row easily using the
DataGridView.DefaultCellStyle.SelectionBackColor
DataGridView.DefaultCellStyle.SelectionForeColor
But what about to leave the selected line with the font in bold? I already tried some things like using the SelectionChanged
event as follows:
private void Grid_SelectionChanged(object sender, EventArgs e)
{
var dataGridView = Grid;
if (dataGridView.SelectedRows.Count > 0)
{
var selectedRow = dataGridView.SelectedRows[0];
selectedRow.DefaultCellStyle.Font = new Font(dataGridView.Font, FontStyle.Bold);
}
}
It turns out that this always leaves all the lines with the font in bold, so it's not quite there.
What's the right way to do this?