2012-04-02 77 views
0

我目前在C#FTP客戶端工作,我需要一些幫助。C#將圖標添加到ListView行

客戶端連接到FTP服務器,檢索目錄並將其名稱顯示爲ListView。

但我也想爲這些目錄/文件顯示一個小圖標,就像在Windows資源管理器中一樣。你知道我在說什麼...

任何人都可以幫我嗎? 謝謝!

LE:

現在我有這樣的方法:

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#...

+0

你能張貼一些示例代碼嗎? – 2012-04-02 18:33:25

回答

2

下載/找到一個適當的圖標,添加一個圖像列表,將您的圖標添加到圖像列表,將ListView.SmallImageList屬性設置爲您的圖像列表,設置行'.SmallIconIndex或.SmallIconImageKey我認爲)到圖像列表中圖像的索引/鍵。

+1

謝謝!我遵循你的步驟,一切正常。 – 2012-04-02 18:58:49

0
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)