ListBox

【計算】

項目筆數

Dim Count = listBox.Items.Count

※索引範圍 0~Count-1

【新增】

Add : 新增至最後面

listBox.Items.Add( string ),加在ListBox最後面,下方顯示的是最新的資料。

listBox.Items.Add(txt_input.text)

listBox.TopIndex = listBox.Items.Count - 1 '紀錄最高索引值

Insert : 指定位置插入新增

listBox.Items.Insert(int a,string str),,加在ListBox最面,方顯示的是最新的資料。

listBox.Items.Insert(0,DateTime.Now.ToString("HH:mm:ss"));


參考文獻:https://www.796t.com/content/1541897947.html

【尋找】

FindString

listBox.FindString(SearchString) '不好用

Foreach 遍尋

For Each i As String In ListBox1.Items

If i = SearchStr Then

SearchSignIn = True

End If

Next

'i是ListBox1的內容字串


【取消選取】

已選取項目反白消失

listBox.ClearSelected()

指定選項:被選項目反白

listBox.SelectedIndex = 索引值