2011-04-12 41 views
0

我有一個datagridview綁定到表。表格的列是IDTransaction金額TransactionType。如何從另一個事件執行事件?

我想根據TransactionType更改Amount單元格的顏色。

if (transactiontype==1) 
    cell.backgroundcolor=red; 
else 
    cell.backgroundcolor=white; 

你在哪裏推薦給我做嗎?(在此情況下)

謝謝

+0

你需要提供更多的上下文,是ASP.NET還是WinForms,你是如何綁定的?有沒有你已經處理的任何綁定事件?你要求推薦,所以你應該給出推薦的所有標準。 – 2011-04-12 08:40:24

回答

0

對於Windows窗體您通常把這個代碼在CellFormatting Event

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 

if (this.dataGridView1.Columns[e.ColumnIndex].Name = "TransactionType") 
{ 

    if (e.Value != null) 
    { 
     if (e.Value == 1) 
     { 
      e.CellStyle.BackColor = Color.Red; 
     } 
     else 
     { 
      e.CellStyle.BackColor = Color.White; 
     } 
    } 
    } 
}