2010-12-07 63 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; 
     } 
    } 
相关问题