更改特定DataGridViewCell的Fore Color [英] Change Fore Color of a specific DataGridViewCell
本文介绍了更改特定DataGridViewCell的Fore Color的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两列的DataGridView。默认的前色为黑色。我想改变具有负值的单元格的前色。我怎样才能实现这个目标?
TotalQty | TotalAmount
---------------------
10 | 10000
-10 | -1000
-12 | -2000
20 | 12000
谢谢!
I have a DataGridView with two Columns. The default fore color is black. I want to change the fore color of the cell which has a minus value. How can i achieve this?
TotalQty | TotalAmount
---------------------
10 | 10000
-10 | -1000
-12 | -2000
20 | 12000
Thanks!
推荐答案
试试这个
Try this
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
// If the column is the Artist column, check the
// value.
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "yourColumnName")
{
if (e.Value != null)
{
// Check for the string "pink" in the cell.
int Value = e.Value;
if (Value<0))
{
e.CellStyle.BackColor = Color.Pink;
}
}
}
}
希望这有帮助
Hope this helps
这篇关于更改特定DataGridViewCell的Fore Color的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文