如何从列表框中删除随机项

How to remove a random item from a ListBox

我无法从 ListBox

中删除随机项目

我试过了,但没用

 Dim rnd As New Random
 Dim randomIndex As Integer = rnd.Next(0, ListBox1.Items.Count)
 ListBox1.Items.Remove(randomIndex)

Remove method takes the actual item to remove, not the index. To remove by index, use RemoveAt:

Dim rnd As New Random
Dim randomIndex As Integer = rnd.Next(0, ListBox1.Items.Count)
ListBox1.Items.RemoveAt(randomIndex)