如何更改排颜色的DataGridView? [英] How to change row color in datagridview?

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

问题描述

我想改变特定行的颜色在我的datagridview。该行应更改为红色时columncell 7的值是columncell 10小于设定值,如何做到这一点有什么建议?

I would like to change the color of a particular row in my datagridview. The row should be changed to red when the value of columncell 7 is less than the value in columncell 10. Any suggestions on how to accomplish this?

推荐答案

您需要通过在DataGridView行中循环,然后在每行比较列7和10的值。

You need to loop through the rows in the datagridview and then compare values of columns 7 and 10 on each row.

试试这个:

foreach (DataGridViewRow row in vendorsDataGridView.Rows) 
     if (Convert.ToInt32(row.Cells[7].Value) < Convert.ToInt32(row.Cells[10].Value)) 
     {
         row.DefaultCellStyle.BackColor = Color.Red; 
     }

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

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