'vb 6.0 delete row from listview1
I just joined the site, I apologize in advance for the wrong English, I used google translate, I used listview1 in vb 6, there is no problem with adding and deleting by clicking What I want to do is to remove the number I wrote in the txtsearch.Text box on the form from the list, not index, it will only remove what I wrote in the txtsearch.Text box.
it should be like in the picture
i tried this but it only deletes as index it doesn't delete the line i wrote
Private Sub Command2_Click()
If ListView1.ListItems.Count <= 0 Then MsgBox "Nothing to remove", vbInformation, "": Exit Sub
ListView1.SelectedItem = ListView1.ListItems(Val(txtsearch.Text))
If vbYes = MsgBox("Are you sure you want to delete the selected item?", vbQuestion + vbYesNo, "") Then
ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
End If
End Sub
thank you for your help
Solution 1:[1]
To select a desired row via the SelectedItem property, the Set keyword must be used.
Alternatively, the Selected property for the desired row can be set to True in order to select that row.
Try this:
Private Sub Command2_Click()
If ListView1.ListItems.Count <= 0 Then
MsgBox "Nothing to remove", vbInformation, ""
Exit Sub
End If
Set ListView1.SelectedItem = ListView1.ListItems(Val(txtsearch.Text))
' Or the following will also work
'ListView1.ListItems(Val(txtsearch.Text)).Selected = True
If vbYes = MsgBox("Are you sure you want to delete the selected item?", vbQuestion + vbYesNo, "") Then
ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
End If
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

