如何設置DataGridViewComboBoxCell中不同項目的字體顏色?例如,如果我有10件物品,我會如何製作物品3和5紅色,並讓其他物品變黑?設置DataGridViewComboBoxCell中項目的字體顏色
編輯:這是一個WinForm應用程序和DataGridViewComboBox未綁定
EDIT2數據:也許我可以在這裏editcontrolshowing做到這一點?
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].Name == "MyCombo")
{
DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)dataGridView1.CurrentCell;
for (int i = 0; i < comboCell.Items.Count; ++i)
{
string contract = comboCell.Items[i].ToString();
if (contract.ToUpper().Contains("NO"))
{
// can I set this item have a red font color???
}
}
}
我下面貼一個快速和骯髒的方法..如果你不想做整個列/行然後更改對象即組合框細胞類似這應該有助於讓你開始.. – MethodMan 2012-02-21 22:18:43
可能的重複[要更改DataGridViewComboBoxCell顏色(樣式)動態](http://stackoverflow.com/questions/7242308/to-change-the-datagridviewcomboboxcell-colorstyle-dynamically) – 2012-02-22 16:42:39