1
In Datagridview of Windows Forms it is possible to change the font color and background color of the selected line easily using the properties
DataGridView.DefaultCellStyle.SelectionBackColor
DataGridView.DefaultCellStyle.SelectionForeColor
But what about leaving the line selected with the font in bold? I’ve tried a few things like using the event SelectionChanged
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 it always leaves all the lines with the font in bold, so it’s not quite there.
What’s the right way to do it?