2015-07-10 69 views

回答

7

请尝试对CellMouseMove事件

private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) 
{ 
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Blue; 
} 

您需要CellMouseLeave事件还原色彩

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) 
{ 
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White; 
} 
+0

您需要一提的'列name'而不是' e.ColumnIndex'为特异细胞。 –

+1

也在DGV构造函数中,您需要设置双缓冲绘制,否则更改单元格样式会引发鼠标移过DGV上的闪烁'this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint,true);' –