如何在ListView中添加和Image到项目? [英] How to add and Image to Item in a ListView?

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

问题描述

大家好,



建议我在列表视图中为项目添加图片?



问候,

Chaithu

Hi All,

Please suggest me in adding an image to an item in the listview?

regards,
Chaithu

推荐答案

如果你想通过代码将图像添加到ListView,你可以这样做:



If you want to add the images to the ListView by code, you can do something like this:

private void Form10_Load(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"c:\pic");
            foreach (FileInfo file in dir.GetFiles())
            {
                try
                {
                    this.imageList1.Images.Add(Image.FromFile(file.FullName));
                }
                catch{
                    Console.WriteLine("This is not an image file");
                }
            }
            this.listView1.View = View.LargeIcon;
            this.imageList1.ImageSize = new Size(32, 32);
            this.listView1.LargeImageList = this.imageList1;
            //or 
            //this.listView1.View = View.SmallIcon;
            //this.listView1.SmallImageList = this.imageList1;
 
            for (int j = 0; j < this.imageList1.Images.Count; j++)
            {
                ListViewItem item = new ListViewItem();
                item.ImageIndex = j;
                this.listView1.Items.Add(item);
            }
        }





希望这对您有帮助。



Hope this might help you.






请查看以下链接:



带有SubItems图像的ListView [ ^ ]

ListView.Items属性 [ ^ ]



亲切问候,
Hi,

Please have a look at the following links:

ListView with Image on SubItems[^]
ListView.Items Property[^]

Kind regards,


试试这个链接

http:// ondotnet .com / pub / a / dotnet / 2002/10/28 / listview.html?page = 2 [ ^ ]



希望有所帮助:)
Try this link
http://ondotnet.com/pub/a/dotnet/2002/10/28/listview.html?page=2[^]

Hope it helps :)


这篇关于如何在ListView中添加和Image到项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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