簡體   English   中英

VB.NET列表框選擇索引

[英]VB.NET Listbox selectedindex

在我的代碼中,我選擇excel文件將其添加到列表框中,然后運行一些代碼,該代碼將替換列表中所有excel文件上的某個單元格。 每次更改excel文件中的單元格時,它將使用以下內容轉到列表框中的下一個單元格:

Me.ListBox2.SelectedIndex = Me.ListBox2.SelectedIndex + 1

但是,當到達列表末尾時,它給我一個錯誤。 我如何讓我的列表框知道它已經結束了。

像這樣檢查:

if Me.ListBox2.SelectedIndex + 1  < Me.ListBox2.items.count then
    Me.ListBox2.SelectedIndex + = 1
End if

我想我會做一個For / Each / Next來遍歷這樣的項目:

For Each ListItem As Object In ListBox2.Items

    'Set Active item as selected
    ListBox2.SelectedItem = ListItem

    'manipulate file
    UpdateExcelFile(ListItem.ToString)

Next

純娛樂。 您可以在不使用IF / END IF的情況下執行此操作
以下代碼將selectedindex移至下一項,直到到達列表框的末尾。

ListBox1.SelectedIndex += Math.Abs(CInt(ListBox1.SelectedIndex < ListBox1.Items.Count - 1))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM