【发布时间】:2020-04-28 06:23:49
【问题描述】:
我正在尝试在ObjectListView 中设置单元格的前景色。 SO和其他网站上有关于这个的问题和答案,建议使用ObjectListView的FormatCell事件。如http://objectlistview.sourceforge.net/cs/recipes.html#how-can-i-change-the-colours-of-a-row-or-just-a-cell中所述
我尝试了代码并且它可以工作,但是当需要重绘单元格时它可以工作(它们最初显示为黑色,并且每个项目我将鼠标移到它上面调用事件)。但我真的不需要一个事件,因为我想设置一个固定的颜色,比如:
foreach (OLVListItem item in olv.Items)
if (item.SubItems[7].Text != "")
{
if (item.SubItems[7].Text.StartsWith("-"))
item.SubItems[7].ForeColor = Color.Red;
else item.SubItems[7].ForeColor = Color.DarkGreen;
}
但上面的代码不影响结果。
【问题讨论】:
标签: c# objectlistview