|
-
Jun 23rd, 2004, 03:32 AM
#1
Thread Starter
New Member
Help needed on ListView
Help... How do i delete a selected item from ListView?
Below is the method i've tried using, but it doesn't work.
VB Code:
Dim i As Integer
For i = 1 To lsvNewContacts.ListItems.Count
lsvNewContacts.ListItems.Remove (i)
Next i
For the method mentioned above, if there's only an item inside the ListView, it works well if i tried deleting that item. However, if there's 2 items in the ListView, it'll still delete the item i've selected but giving me the error 'Index out of bound' at the same time.
Is there anyone out there that can help me with this problem? Thank you and oh by the way I am currently using visual basic 6.
-
Jun 23rd, 2004, 03:58 AM
#2
Fanatic Member
i do this in vb.net but i don't know vb6.
VB Code:
Dim li As ListViewItem
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
ListView1.Items.Remove(li)
End Sub
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
li = ListView1.GetItemAt(e.X, e.Y)
End Sub
if double clicked, it removes the selected item.
-
Jun 23rd, 2004, 04:01 AM
#3
Hyperactive Member
Try this:
Code:
Dim lst As ListViewItem
For Each lst In Me.LswScadenze.SelectedItems
lst.Remove()
Next
Good job
Live long and prosper (Mr. Spock)
-
Jun 23rd, 2004, 04:15 AM
#4
Thread Starter
New Member
Both methods doesn't work but i really appreciates your help. Thanks alot. >.<
-
Jun 23rd, 2004, 05:36 AM
#5
Hyperactive Member
Uhmmm....Caresse, I did a quick test of my code. It seems work, at least for a single item (I tried in a my project where I have a ListView on which multiple selection is inibithed). It deleted the selected item in my test! My method should be able to remove multiple selected items, too.
The code of Brown Monkey (Hi B.M., happy to meet you again! ) seems good, also. Could you describe the problem you encounter, or post some more code and details?
Live long and prosper (Mr. Spock)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|