如何使ListView中的项目具有不同的颜色? [英] How do I make the items in a ListView a different color?

查看:90
本文介绍了如何使ListView中的项目具有不同的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个装满ListViewItems的ListView.

I have a ListView full of ListViewItems.

当某个事件触发时,我想强调其中的一些,所以我正在寻找一种将列表视图的颜色更改为黑色以外的颜色(红色会很有趣)的方法.

I want to emphasize some of them when a certain event fires, so I'm looking for a way to change the color of the listview to something other than black (red would be delightful).

是否可以动态更改默认Winforms ListView中项目的颜色?

Is it possible to dynamically change the color of the items in the default winforms ListView?

如果否,是否有一些简单的方法可以动态地强调项目?

If no, is there some easy way to otherwise emphasize the items dynamically?

推荐答案

列表视图项的颜色直截了当:

The color of a list view item is straight forward:

ListViewItem li = new ListViewItem();
li.ForeColor = Color.Red;
li.Text = "Sample";
listView1.Items.Add(li);

更改列表视图本身的背景颜色仅仅是listView1.BackColor = Colors.Red;

Changing the background color of the list view itself is just listView1.BackColor = Colors.Red;

修改ListView中的一项:

Modifying an item in the ListView:

foreach(ListViewItem li in listView1)
{
   if(li.Text = "Sample")
   {
     li.ForeColor = Color.Green;
   }
}

这篇关于如何使ListView中的项目具有不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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