I'm trying to change the color of the row header in a data grid view after clicking.
private void DGV_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
var row = DGV.Rows[e.RowIndex];
row.HeaderCell.Style.BackColor = Color.Yellow;
row.HeaderCell.Style.ForeColor = Color.Yellow;
}
However, the color is never changed?
To show different color than the visual styles color, you need to set EnableHeadersVisualStyles
of the DataGridView
to false.
If you want row headers show a yellow background color when you select the row, you have a better option than handling click event of the row headers:
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Yellow;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.