在分项的ListView图片 [英] Images in ListView subitem

查看:159
本文介绍了在分项的ListView图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加图片代替文字的列表视图子项?如 http://i44.tinypic.com/2mzz6s6.png

How to add an image instead of text for a listview subitem? Like http://i44.tinypic.com/2mzz6s6.png ?

在这里通常是我如何添加一个字符串:

here is normally how I add a string:

ListViewItem item = new ListViewItem("A");
item.SubItems.Add("B");
item.SubItems.Add("C");
listView1.Items.AddRange(new ListViewItem[] { item });

我使用.NET 2.0的WinForms。另外,请不要链接我具有超强的.NET列表视图控件的文章。我要坚持标准之一MSVC。

I am using .NET 2.0 with WinForms. Also, please don't link me to articles with superior .NET listview controls. I want to stick to the standard one in MSVC.

推荐答案

如果您需要的图标将在第一列,那么它可以很容易地创建一个的ImageList 您要显示图像,将其分配到的的ListView SmallImageList 属性和设置相应的的ImageIndex 的项目。像这样的:

If you need the icon to be in the first column, then it could be easily done by creating an ImageList with images you want to display, assigning it to the SmallImageList property of the ListView and setting appropriate ImageIndex for the item. Like this:

listView1.SmallImageList = YourImageList;
ListViewItem lvi = new ListViewItem();
lvi.SubItems.Add("A");
lvi.SubItems.Add("B");
lvi.SubItems.Add("C");
lvi.ImageIndex = 2; // this will display YourImageList.Images[2] in the first column
listView1.Items.Add(lvi);

这篇关于在分项的ListView图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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