VB.NET中如何删除listbox中的最大值

Dim max As Integer
Dim ID As Single
max = ListBox1.Items(0)
ID = 1
Dim i%
For i = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i) > max Then
ID = i
End If
Next i
ListBox1.Items.Remove(ID)
我按照VB的改了下但是没效果,有高人可以解答不。。。。。。

max是要保存最大值的,你每次改变ID = i的时候都没有更新最大值max,所以要改:
For i = 0 To ListBox1.Items.Count - 1
If Val(ListBox1.Items(i)) > max Then
max=CInt(ListBox1.Items(i))
ID = i
End If
Next i
还有你的ID更新也有问题,一开始的时候似乎应该是ID=0,而不是ID=1。
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜