DataGridViewマウスカーソルがある一行(レコード)の色を変える
またまた、DataGridViewネタをひとつ
マウスカーソルがある一行(レコード)の色を変える。
private void dataGridViewRecords_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewCellStyle dcs = new DataGridViewCellStyle(); dcs.BackColor = Color.Yellow; DataGridView dgv = (DataGridView)sender; for (int rowIndex = 0; rowIndex < dgv.Rows.Count; rowIndex++) { dgv.Rows[rowIndex].DefaultCellStyle = null; } if (e.RowIndex >= 0) { dgv.Rows[e.RowIndex].DefaultCellStyle = dcs; } }
DataGridViewで表示レコード数が多い場合でも
これだとどこにマウスカーソルがあるか一目でわかる。