https://www.daniweb.com/programming/software-development/threads/423089/datagridview-changing-the-font-to-bold-when-a-mouse-is-hover-over-a-row
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class DataGridWithBoldForm : Form
{
private DataSet _data;
private DataGridViewCellStyle _normalStyle;
private DataGridViewCellStyle _boldStyle;
public DataGridWithBoldForm()
{
InitializeComponent();
// define styles
_normalStyle = new DataGridViewCellStyle();
_normalStyle.Font = new System.Drawing.Font("Arial", 10F, FontStyle.Regular);
_boldStyle = new DataGridViewCellStyle();
_boldStyle.Font = new System.Drawing.Font("Arial", 10F, FontStyle.Bold);
// get data
_data = new DataSet("People");
_data.ReadXml(@".\People.xml");
// bind data to control
dataGridView1.DataSource = _data;
dataGridView1.DataMember = "Person";
// add event listeners
dataGridView1.CellMouseEnter += new DataGridViewCellEventHandler(dataGridView1_CellMouseEnter);
dataGridView1.CellMouseLeave += new DataGridViewCellEventHandler(dataGridView1_CellMouseLeave);
}
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
var rowIndex = e.RowIndex;
if (rowIndex < 0 || rowIndex >= dataGridView1.Rows.Count)
{
return;
}
dataGridView1.Rows[rowIndex].DefaultCellStyle = _boldStyle;
}
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
var rowIndex = e.RowIndex;
if (rowIndex < 0 || rowIndex >= dataGridView1.Rows.Count)
{
return;
}
dataGridView1.Rows[rowIndex].DefaultCellStyle = _normalStyle;
}
}
}