I want to delete an item from a list and from a database. This is the code I used:
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
But it don’t work.. The error is:
Conversion from string “System.Windows.Forms.ListBox, It” to type
‘Integer’ is not valid.
But when I type Nr = 83 (83 is my UserID for a patiënt) it worked.
Can somebody please help me?
You need to change
s = lstPatiënten.ToStringtos = lstPatiënten.SelectedItem.ToString. Give that a whirl and let me know if it works.Listbox.SelectedItem