dataGridView如何根据单元格的值设置单元格的颜色

侧卫战机 2014-09-20 03:29:02

if (dataGridView1.Rows[2].Cells[2].Value.ToString > 0)
{
dataGridView1.Rows[2].Cells[2].Style.ForeColor = Color.Red;
dataGridView1.Rows[2].Cells[3].Style.ForeColor = Color.Red;
dataGridView1.Rows[2].Cells[4].Style.ForeColor = Color.Red;
}
else
{
dataGridView1.Rows[2].Cells[2].Style.ForeColor = Color.Green;
dataGridView1.Rows[2].Cells[3].Style.ForeColor = Color.Green;
dataGridView1.Rows[2].Cells[4].Style.ForeColor = Color.Green;
}
帮忙改错.
...全文
203 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
侧卫战机 2014-09-20
  • 打赏
  • 举报
回复
错误 1 与“System.Convert.ToInt32(object)”最匹配的重载方法具有一些无效参数 D:\My Documents\Visual Studio 2008\Projects\Test01\Test01\Form1.cs 26 17 Test01 错误 2 参数“1”: 无法从“方法组”转换为“object” D:\My Documents\Visual Studio 2008\Projects\Test01\Test01\Form1.cs 26 33 Test01
全栈极简 2014-09-20
  • 打赏
  • 举报
回复
字符串不好直接跟整数比较,需要转换为int型。 dataGridView1.Rows[2].Cells[2].Value.ToString => Convert.ToInt32(dataGridView1.Rows[2].Cells[2].Value.ToString);
侧卫战机 2014-09-20
  • 打赏
  • 举报
回复
错误在这理: if (dataGridView1.Rows[2].Cells[2].Value.ToString > 0) 不知如何处理。
全栈极简 2014-09-20
  • 打赏
  • 举报
回复
背景色应该是BackColor吧? dataGridView1.Rows[2].Cells[2].Style.BackColor= Color.Red;

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧