如何在VB.net中使用CInt和Split从列表中删除项目

如何在VB.net中使用CInt和Split从列表中删除项目,vb.net,string,list,split,int,Vb.net,String,List,Split,Int,我想从列表和数据库中删除项目。这是我使用的代码: Dim nr As Integer Dim s As String s = lstPatiënten.ToString nr = CInt(s.Split("-"c)(0)) For Each d In patienten If d.nr = nr Then If patientenDB.PatientVerwijderen(d

我想从列表和数据库中删除项目。这是我使用的代码:

Dim nr As Integer
        Dim s As String
        s = lstPatiënten.ToString
        nr = CInt(s.Split("-"c)(0))
        For Each d In patienten
            If d.nr = nr Then
                If patientenDB.PatientVerwijderen(d) > 0 Then
                    initGetPatienten()
                End If
            End If
        Next
但是它不起作用。。错误是:

从字符串“System.Windows.Forms.ListBox,It”转换为类型 “整数”无效

但是当我输入Nr=83(83是我的patiënt用户ID)时,它起作用了


有人能帮我吗?

您需要将
s=lstpatinten.ToString
更改为
s=lstpatinten.SelectedItem.ToString
。试一试,让我知道它是否有效