2016-09-22 26 views
0

我使用以下代碼更改datagridview的CellEnter事件中的單元格樣式。但如果我刪除if語句,所有行都將在數據綁定後格式化爲粗體。任何提示或建議?在RowIndex上更改DataGridviewCellStyle 0

DataGridViewCellStyle oStyle = new DataGridViewCellStyle(); 
      oStyle.Font = new Font("Microsoft Sans Serif", 9.25f, FontStyle.Bold); 

      if (e.RowIndex > 0) 
      { 
       dataGridView1.Rows[e.RowIndex].Cells[0].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[1].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[2].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[3].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[4].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[5].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[6].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[7].Style = oStyle; 
       dataGridView1.Rows[e.RowIndex].Cells[8].Style = oStyle; 
      } 

回答

0

如果我理解你所期望的行爲正確。 您可以嘗試將上面的代碼添加到CellMouseClick事件中。