如何更改datagridview中的行颜色? [英] How to change row color in datagridview?
本文介绍了如何更改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屋!
查看全文