2010-12-07 90 views
1

我在Windows窗體中有一個datagrid(不是gridview或datagridview)。它是在Microsoft Visual Studio 2003中創建的。我已轉換爲2008.我應該根據條件更改數據網格的數據行。如何以編程方式爲數據網格行設置背景顏色

我用Google搜索,發現了一些例子,如

無效myDataGrid_LoadingRow(對象發件人,DataGridRowEventArgs E)

但我沒有任何 「DataGridRowEventArgs」 的論點。

還我發現

http://www.syncfusion.com/faq/windowsforms/faq_c44c.aspx,他們改變一個特定的細胞的顏色之一。

但是,如何根據某些條件更改Windows窗體中Datagrid中整行的顏色。

在此先感謝。

問候

SKR

回答

0

將此作爲暗示:

private void dataGridView1_CellFormatting(object sender,   DataGridViewCellFormattingEventArgs e) 
{ 
    foreach (DataGridViewRow Myrow in dataGridView1.Rows) 
    {   //Here 2 cell is target value and 1 cell is Volume 
     if (Convert.ToInt32(Myrow .Cells[2].Value)<Convert.ToInt32(Myrow .Cells[1].Value))// Or your condition 
     { 
      Myrow .DefaultCellStyle.BackColor = Color.Red; 
     } 
     else 
     { 
      Myrow .DefaultCellStyle.BackColor = Color.Green; 
     } 
    } 
相關問題