想要更改ListViewItem子项之一的背景颜色。但没有任何反应。为什么?的Winforms
if (tmp.points == 100) {
//ListViewItem.ListViewSubItem li = new ListViewItem.ListViewSubItem(tmp_item,tmp.verdict);
//li.BackColor = Color.Green;
//tmp_item.SubItems.Add(li);
tmp_item.SubItems.Add(tmp.verdict,Color.Red,Color.Green, new System.Drawing.Font("Microsoft Sans Serif", 20) );
} else if (tmp.points == 0) {
tmp_item.SubItems.Add(tmp.verdict,Color.Black,Color.Red, new System.Drawing.Font("Arial", 20) );
} else {
tmp_item.SubItems.Add(tmp.verdict,Color.Black,Color.Yellow, new System.Drawing.Font("Arial", 20) );
}
答案 0 :(得分:0)
最有可能的是,ListViewItem的UseItemStyleForSubItems属性为true,它会覆盖此属性。将该属性设置为true,然后尝试:
myListView.Items[0].UseItemStyleForSubItems = false;
// Then for the subitems
tmp_item.SubItems.ForeColor = Color.Red;