2015-07-10 73 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);' –