且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在vb中删除列表框中的项目

更新时间:2023-11-28 21:24:16

通过按 Button2 ListBox 中删除项目时, SelectedIndexChanged ListBox1 的/code>被调用.在那里,所选项目将一无所有,因此要解决此问题,请在分配字符串变量之前在 SelectedIndexChanged事件中添加以下行.

When you remove an item from the ListBox by pressing the Button2, the SelectedIndexChanged of the ListBox1 is being called. There, the selected item will be nothing, so to solve this, add the following lines inside the SelectedIndexChanged event before assigning the string variable.

    If ListBox1.SelectedItem Is Nothing Then
        Exit Sub
    End If