为什么我的输出显示具有不同图标的相同文件名的多个实例 [英] Why is my output showing multiple instances of the same filename with different icons

查看:72
本文介绍了为什么我的输出显示具有不同图标的相同文件名的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string[] fileEntries = Directory.GetFiles(tbDirectory.Text);

                foreach (string filename in fileEntries)
                {
                    Icon ico = Icon.ExtractAssociatedIcon(filename.ToString());
                    smallImageList.Images.Add(ico);
                    //long fileSize = new System.IO.FileInfo(filename).Length;

                    for (int i = 0; i < fileEntries.Length; i++)
                    {
                        //lvi.SubItems.Add(GetSizeReadable(fileSize));
                        lvSums.Items.Add(filename.ToString().ToLower(), i);
                    }
                }
                foreach (ColumnHeader columns in lvSums.Columns)
                    columns.Width = -2;





我试图在列表视图中添加带有文件名的受尊重图标,没有按计划进行。



I am trying to add to the listview the respected icon with its filename, no going as planned.

推荐答案

我找到了它:

拿出for循环并添加了类型int indexx并为每个文件递增添加。效果很好。



I found it:
Took out the for loop and just added type int indexx and incremented for each file added. Works perfect.

try
           {
               string[] fileEntries = Directory.GetFiles(tbDirectory.Text);

               foreach (string filename in fileEntries)
               {
                   Icon ico = Icon.ExtractAssociatedIcon(filename.ToString());
                   smallImageList.Images.Add(ico);
                   //long fileSize = new System.IO.FileInfo(filename).Length;

                   //for (int i = 0; i < fileEntries.Length; i++)
                   //{
                       //lvi.SubItems.Add(GetSizeReadable(fileSize));
                       lvSums.Items.Add(filename.ToString().ToLower(), index);
                       index++;
                   //}
               }
               foreach (ColumnHeader columns in lvSums.Columns)
                   columns.Width = -2;
           }
           catch { Exception ex;}


这篇关于为什么我的输出显示具有不同图标的相同文件名的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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