我怎样才能改变一个子项的前景色ListView控件? [英] How can I change the ForeColor of a single sub item in a ListView control?

查看:174
本文介绍了我怎样才能改变一个子项的前景色ListView控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序中,我有一个的ListView 控制。我想换一个子项的前景色。虽然我已成功地改变整行或列的颜色,我还没有想出一个办法做到这一点的一个子项目。有谁知道的一种方式做到这一点?

I have a Windows Form application in which I have a ListView control. I want to change the forecolor of a single subitem. Although I have managed to change the color of a entire row or column, I haven't figured out a way to do this for a single subitem. Does anyone know of a way to do this?

推荐答案

解决的方法是相当简单的,并且显示在该<一个文档的备注部分href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.listviewsubitem.forecolor.aspx"><$c$c>ListViewSubItem.ForeColor物业:

The solution is fairly simple, and is indicated in the Remarks section of the documentation for the ListViewSubItem.ForeColor property:

如果的的ListViewItem 拥有该子项的 UseItemStyleForSubItems 属性设置为true,则设置此属性没有的效果。

If the UseItemStyleForSubItems property of the ListViewItem that owns the subitem is set to true, setting this property has no effect.

默认设置的目的是保持一致的外观在的ListView 控制由单个项目所拥有的所有子项,这样你只需要在一个地方更改属性。 要更改默认行为,您需要设置<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.useitemstyleforsubitems.aspx"><$c$c>UseItemStyleForSubItems特定财产 的ListViewItem 为假。

The default setting is intended to maintain a consistent appearance for all subitems owned by a single item in a ListView control so that you only have to change the properties in one place. To change the default behavior, you need to set the UseItemStyleForSubItems property of a particular ListViewItem to "False".

一旦你做到了这一点,你可以调整前景色(或任何其他)个别分项的财产。例如:

Once you've done that, you can adjust the ForeColor (or any other) property of an individual subitem. For example:

myListView.Items[0].UseItemStyleForSubItems = false;
myListView.Items[0].SubItems[1].ForeColor = Color.Red;

这篇关于我怎样才能改变一个子项的前景色ListView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆