我正在創建基於表單和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