【问题标题】:How do I set background color for a datagrid row programmatically如何以编程方式为数据网格行设置背景颜色
【发布时间】:2010-12-07 17:32:42
【问题描述】:

我在 Windows 窗体中有一个数据网格(不是 gridview 或 datagridview)。它是在 Microsoft Visual Studio 2003 中创建的。我已转换为 2008。我应该根据条件更改数据网格的数据行。

我用谷歌搜索并找到了一些例子,例如

void myDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)

但我没有任何“ DataGridRowEventArgs ”参数。

我也发现了一个

http://www.syncfusion.com/faq/windowsforms/faq_c44c.aspx,它们会改变一个特定单元格的颜色。

但是如何根据某些条件更改 Windows 窗体中 Datagrid 中整行的颜色。

提前致谢。

问候

skr

【问题讨论】:

    标签: winforms c#-3.0


    【解决方案1】:

    以此为提示:

        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; 
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 2023-03-26
      • 2014-06-24
      • 2011-06-13
      • 1970-01-01
      • 2021-05-20
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多