改变datagridview的单元格颜色动态 [英] Changing datagridview cell color dynamically
本文介绍了改变datagridview的单元格颜色动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用数据填充一个DataGridView对象。我想点击一个按钮,把它改变细胞的背景颜色。这是我目前有
I have a dataGridView object that is populated with data. I want to click a button and have it change the color of the background of the cell. This is what I currently have
foreach(DataGridViewRow row in dataGridView1.Rows)
{
foreach(DataGridViewColumn col in dataGridView1.Columns)
{
//row.Cells[col.Index].Style.BackColor = Color.Green; //doesn't work
//col.Cells[row.Index].Style.BackColor = Color.Green; //doesn't work
dataGridView1[col.Index, row.Index].Style.BackColor = Color.Green; //doesn't work
}
}
这三个原因表格以重叠的方式被重画在其自身上,并试图重新大小的表变得一团糟。在一个单元格,当点击,值保持高亮显示,背景色不会改变。
ALL of these three cause the table to be redrawn over itself in an overlapping manner and trying to re-size the tables becomes a mess. when clicking on a cell, the value remains highlighted and the backcolor doesn't change.
问:我怎样才能更改单个单元格的背景色表中存在之后
Q: How can I change the backcolor of an individual cell after the table exists?
推荐答案
这对我的作品
dataGridView1.Rows[rowIndex].Cells[columnIndex].Style.BackColor = Color.Red;
这篇关于改变datagridview的单元格颜色动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文