C#将图标添加到ListView行

C#将图标添加到ListView行,c#,listview,icons,C#,Listview,Icons,我目前在一个C#FTP客户端工作,我需要一些帮助 客户端连接到FTP服务器,检索目录并将其名称显示到ListView中 但我还想为这些目录/文件显示一个小图标,类似于在Windows资源管理器中。你知道我在说什么 有人能帮我吗? 谢谢 乐: 现在我有了这个方法: private void listFiles(String path) { connection = (FtpWebRequest)FtpWebRequest.Create(path);

我目前在一个C#FTP客户端工作,我需要一些帮助

客户端连接到FTP服务器,检索目录并将其名称显示到ListView中

但我还想为这些目录/文件显示一个小图标,类似于在Windows资源管理器中。你知道我在说什么

有人能帮我吗? 谢谢

乐:

现在我有了这个方法:

private void listFiles(String path)
        {
           connection = (FtpWebRequest)FtpWebRequest.Create(path);
           connection.Method = WebRequestMethods.Ftp.ListDirectory;
           WebResponse response = connection.GetResponse();
           StreamReader reader = new StreamReader(response.GetResponseStream());
           string line = reader.ReadLine();
           while (line != null)
           {
               listView1.Items.Add(new ListViewItem(line));               
           }
        }

我应该补充什么?我不熟悉c#…

下载/找到合适的图标,添加imagelist,将图标添加到imagelist,将ListView.SmallImageList属性设置为imagelist,将rows.SmallIconIndex或.SmallIconImageKey(我认为)设置为imagelist中图像的索引/键。

如果是wpf ListView,可以使用DataTemplate
If it's a wpf listview you can use the DataTemplate

<ListView>
      <ListView.ItemTemplate>
          <DataTemplate>
               .. image and <TextBlock> binded to the property you want to show (probably the file name)
.. 图像并绑定到要显示的属性(可能是文件名)
您可以发布一些示例代码吗?