2017-04-01 123 views
1

我不明白這個錯誤,當我添加文件到我的Listviwe同時從選定的文件中的功能extarct圖標,並添加extarced圖標到圖像列表,但是當我選擇多於15個文件時,這個錯誤信息出現 「無效的參數=值'15'對'StateImageIndex'無效。無效的參數=值'15'無效'StateImageIndex'

這裏是我的代碼:

Dim ofg As New OpenFileDialog 
    Dim lvp As New ListViewItem 

    ofg.Multiselect = True 
    ofg.Filter = "All Files|*.*" 

    If ofg.ShowDialog = Windows.Forms.DialogResult.OK Then 
     For Each File As String In ofg.FileNames 

      Dim hInst As IntPtr = Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly.GetModules()(0)) 
      Dim iIcon As Int32 = 0 
      Dim hIcon As IntPtr 

      hIcon = ExtractAssociatedIcon(hInst, File, iIcon) 
      ico = Icon.FromHandle(hIcon) 
      icondufile = ico.ToBitmap 

      Img.Images.Add(icondufile) 

      Dim C_File As New IO.FileInfo(File) 

      Dim ItemFile As ListViewItem = New ListViewItem(C_File.Name) 
      lvp = Files_List.Items.Add(ItemFile) 
      lvp.SubItems.Add(MD5Checksum(File)) 
      lvp.SubItems.Add(hash_generator("sha1", File)) 
      lvp.SubItems.Add(hash_generator("sha256", File)) 
      lvp.SubItems.Add(GetCRC32(File)) 
      lvp.SubItems.Add(hash_generator("sha384", File)) 
      lvp.SubItems.Add(hash_generator("sha512", File)) 
      lvp.SubItems.Add(C_File.FullName) 
      lvp.SubItems.Add(C_File.Extension) 
      Dim Index As Integer 

      lvp.StateImageIndex = lvp.Index 'The error comes from here 

      ItemFile = Nothing 

     Next 

回答

0

根據文檔:

雖然在StateImageList屬性指定的ImageList中可以包含任意數量的圖像,以及StateImageIndex屬性可以設置爲任何等於或低於14的值,僅索引位置0和1處的圖像顯示爲狀態圖像。

那麼你想用StateImageList屬性做什麼?你爲什麼將它設置爲大於14的值?

+0

因爲如果我不設置StateImageList索引沒有狀態圖像將顯示:(幫助Plz !! –

+0

你有超過14個狀態圖像?根據文檔,只有前兩個(索引0和1)被使用所以你應該設置'StateImageIndex'爲0或1,這取決於你想顯示哪一個。 –

+0

圖像列表是空的,當我將文件添加到列表中時,BMP圖像將被添加到圖像列表'Img。 Images.Add(icondufile)「,然後當我添加更多的15個文件時出現錯誤信息,當我看到多少圖像,我在我的圖像列表中,我發現我喜歡如果我添加20個文件,我發現20個圖像在圖像列表中,問題是我怎麼能顯示更多然後14 statimage的15個文件後發生了什麼預覽.... https://ibb.co/n1FKYv –