2011-06-16 39 views
1

這可能也很容易。但我有這個listview包含我列出的exe文件。現在,我想依次執行這些exe文件,從哪些項目進行檢查或不。VB.NET - 對於列表視圖中的每個選中的項目

所以,我已經試過這樣:

For each item in listView1.CheckedItems 
    Msgbox item.ToString 
Next 

因爲我注意到,在checkedItems該項目不包含多。如果我將它轉換爲字符串,它會在msgbox中看起來像這樣:ListViewItem: {Filename.exe}

現在,我明顯需要文件名。但是有沒有其他的方法來提取名字?或者我必須去掉字符串以將ListViewItem: {部分去掉?

回答

4

您的第一步應該是諮詢documentation of ListViewItem以瞭解如何從對象中檢索所需的信息。

Text屬性是你所追求的。

For Each item in listView1.CheckedItems 
    MsgBox(item.Text) 
Next 
+0

對不起,intellisense沒有顯示Item屬性。我認爲那裏有一些屬性:)這會很好地清除它:)然後你每天都會學到一些新的東西! :) – 2011-06-16 11:33:09

1
For each item in listView1.CheckedItems 
    Msgbox item.Text 
Next 

這應該適用的WinForms。

0

你試過Msgbox item.Text

0

您可能會尋找更多像這樣的東西。這將有項目和子項目。你需要一個循環來完成這個。希望這可以幫助

 Dim x As Integer = 0 
    Dim y As Integer = 0 
    For Each item In listView1.CheckedItems 
     For Each subitem In listView1.CheckedItems(y).SubItems 
      MsgBox(subitem.Text) 
      x = x + 1 
     Next 
     y = y + 1 
    Next