我正在创建基于表单和DataGridView
控件的应用程序。根据其价值改变单元格样式?
我从数据库绑定信息,现在我想要做的是根据其值可以是"Urgent","Haute","Normale"
更改列propeties的字体样式和颜色。
这是我正在使用的代码,但它没有奏效,可能有人告诉我下面的代码出了什么问题?
代码:
private void ColorizeCellsbyValue() {
DataGridViewCellStyle BoldRed = null;
BoldRed = new DataGridViewCellStyle();
BoldRed.Font = new Font("Tahoma", 9, FontStyle.Bold);
BoldRed.ForeColor = Color.Red;
DataGridViewCellStyle Red = null;
Red = new DataGridViewCellStyle();
Red.ForeColor = Color.Red;
DataGridViewCellStyle Black = null;
Black = new DataGridViewCellStyle();
Black.ForeColor = Color.Black;
string priority;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
priority = row.Cells[3].Value.ToString();
switch (priority)
{
//Change font
case "Urgent":
row.Cells[3].Style = BoldRed;
break;
case "Haute":
row.Cells[3].Style = Red;
break;
case "Normale":
row.Cells[3].Style = Black;
break;
default:
row.Cells[3].Style = Black;
break;
}
}
}
+1可惜OP希望_“更改字体样式” _': D' – spajce 2013-02-08 12:06:18
@spajce已更新为Fore颜色:) – Ravia 2013-02-08 12:56:59
它似乎不想格式化您的答案? ':D' – spajce 2013-02-08 13:02:49