C#如何让DataGridView某一单元格变色?

crecrecre 2009-01-12 01:08:17
姓名 数学 语文 英语
张三 80 90 60
李四 60 80 90
王五 90 60 80

让60分变色的代码如何写?
...全文
1265 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
流年岁月 2009-01-16
  • 打赏
  • 举报
回复
呵呵还有种简单的,在C#后台 this.gridVIew.items[i][第几列].text= "<Font Color='Red'> 60 </Font>";
消失的尘芥 2009-01-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ljhcy99 的回复:]

比如背景色变成红色,前景色就设置ForeColor

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
for(int j=1;j <4;j++)
if (dataGridView1.SelectedRows[i].Cells[j].Value = "60")
{

[/Quote]
up
HDNGO 2009-01-12
  • 打赏
  • 举报
回复
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name != "姓名")
{
if (e.Value != null)
{
int num = (int)e.Value;
if (num <= 60)
{
e.CellStyle.BackColor = Color.Red;
}

}
}
}
lvg 2009-01-12
  • 打赏
  • 举报
回复
up
jacklee_008 2009-01-12
  • 打赏
  • 举报
回复
鼠标点击一列显示对应的整行变色:
在属性里设置SelectionMode的属性为FullRowSelect
风之影子 2009-01-12
  • 打赏
  • 举报
回复
2楼正解
ljhcy99 2009-01-12
  • 打赏
  • 举报
回复
修改了。

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.RowCount;i++)
{
for(int j=1;j<4;j++)
if (dataGridView1.Rows[i].Cells[j].Value = "60")
{
dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Red;

}
}

}

ljhcy99 2009-01-12
  • 打赏
  • 举报
回复

比如背景色变成红色,前景色就设置ForeColor

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
for(int j=1;j<4;j++)
if (dataGridView1.SelectedRows[i].Cells[j].Value = "60")
{
dataGridView1.SelectedRows[i].Cells[j].Style.BackColor = Color.Red;
}
}
}
hb0513 2009-01-12
  • 打赏
  • 举报
回复
在控件的绑定事件里判断 等于60把相应的字体颜色或者背景都可以改

110,499

社区成员

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

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

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