在datagridview中更改颜色 [英] changing colors in datagridview

查看:74
本文介绍了在datagridview中更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想把我的数据网格视图中的任何颜色放在< 5



我尝试了类似的东西,但它不起作用



Hi Everyone,

I wanna put any color in my datagrid view in a row that is < 5

I tryied something like that but it doesnt work

if (siDataSet.vine.MinimalColumn <= 5)
           {
           this.vineDataGridView.Rows[RowIndex].DefaultCellStyle.BackColor = Color.Red;





}

任何想法?



}
any idea ?

推荐答案

如果你正在尝试指出少于5列,

尝试通过datagridview的行和单元格进行迭代,

If you are trying to point out there are less than 5 columns,
Try to itterate through the rows and cells of the datagridview,
foreach (DataGridViewRow r in dataGridView1.Rows)
           {
               if (r.Cells.Count <= 5)
               {
                   foreach (DataGridViewCell c in r.Cells)
                   {
                       if (c.OwningColumn.HeaderText == "The text of the header")
                       {
                           c.OwningColumn.DefaultCellStyle.BackColor = Color.Red;
                       }
                   }
               }
           }


这将有助于你..

http://www.dotnetperls.com/datagridview-tutorial [ ^ ]
this will help you..
http://www.dotnetperls.com/datagridview-tutorial[^]


如果你确定的价值是单元格是一个数字

你可以试试这个。

If you are sure the value of the cell is a number
you can try this.
DataGridViewCellStyle cs = new DataGridViewCellStyle();
           cs.BackColor = Color.LightBlue;
           foreach (DataGridViewRow r in dataGridView1.Rows)
           {
                   foreach (DataGridViewCell c in r.Cells)
                   {
                       int i = int.Parse(c.Value.ToString());
                       if (i <= 6)
                       {
                           c.Style = cs;
                       }
                   }
               }
           }


这篇关于在datagridview中更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆