|
-
Mar 16th, 2009, 11:17 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2008] Help with listview
Is there any way, to delete a single row in ListView?
Last edited by tassa; Mar 16th, 2009 at 11:24 AM.
-
Mar 16th, 2009, 11:49 AM
#2
Re: [2008] Help with listview
Delete the row from the data source from which the listview was loaded, clear, and reload the listview.
-
Mar 16th, 2009, 02:07 PM
#3
Re: [2008] Help with listview
ListView1.Items.RemoveAt(index)
-
Mar 16th, 2009, 04:00 PM
#4
Thread Starter
Fanatic Member
Re: [2008] Help with listview
Noted....... But is there a way to be able to delete the selected index....???
-
Mar 16th, 2009, 04:06 PM
#5
Re: [2008] Help with listview
Assuming you do not allow MultiSelect, there will only be one selected item so;
If ListView1.SelectedItems.Count > 0 Then
ListView1.Items.RemoveAt(ListView1.SelectedIndices(0))
End If
-
Mar 16th, 2009, 04:07 PM
#6
Thread Starter
Fanatic Member
Re: [2008] Help with listview
And if by any chance i had allowed MultiSelect...?
-
Mar 16th, 2009, 04:10 PM
#7
Re: [2008] Help with listview
For Each lvi As ListViewItem In ListView1.SelectedItems
lvi.Remove()
Next
You could use this whether you have MultiSelect or not.
-
Mar 16th, 2009, 04:16 PM
#8
Re: [2008] Help with listview
loop backwards through the collection, removing the selected items.
Code:
For i As Integer = (ListView1.Items.Count - 1) To 0 Step -1
If ListView1.Items(i).Selected Then
ListView1.Items.RemoveAt(i)
End If
Next
if you don't loop backwards, as soon as you remove an element from the collection, and try to move forwards, you will get an error.
-
Mar 16th, 2009, 04:16 PM
#9
Re: [2008] Help with listview
 Originally Posted by Bulldog
For Each lvi As ListViewItem In ListView1.SelectedItems
lvi.Remove()
Next
You could use this whether you have MultiSelect or not.
this will not work, for the reasons stated in my above post.
EDIT: sorry, my bad... i thought you were looping 'items'... you can do this loop on selected items.
-
Mar 16th, 2009, 04:17 PM
#10
Thread Starter
Fanatic Member
Re: [2008] Help with listview
Both of them work perfectly! Thanks!
But i have one more question...: I have the items of the LV loaded from a text file. I want to delete the file when the selected item is removed from the LV...
If I have "OMG.txt" and in the ListView I have:
111 OMG 111 *In different Columns*
How can i delete that file?
-
Mar 16th, 2009, 04:21 PM
#11
Re: [2008] Help with listview
so that would mean to say that column index 1 (second column) would have the name of the file, minus the .txt part?
I think it is also important to know the actual path to the file, and not just its name. Do these files sit in the same directory as the exe?
-
Mar 16th, 2009, 04:22 PM
#12
Re: [2008] Help with listview
 Originally Posted by kleinma
this will not work, for the reasons stated in my above post.
EDIT: sorry, my bad... i thought you were looping 'items'... you can do this loop on selected items.
No probs.
-
Mar 16th, 2009, 04:22 PM
#13
Thread Starter
Fanatic Member
Re: [2008] Help with listview
Yeah, the column index 1 would have the file name minus the .txt part. The path of the file would be the same as the .exe
-
Mar 16th, 2009, 04:28 PM
#14
Re: [2008] Help with listview
try this:
vb Code:
For Each lvi As ListViewItem In ListView1.SelectedItems
IO.File.Delete(lvi.SubItems(1).Text & ".txt")
lvi.Remove()
Next
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 16th, 2009, 06:38 PM
#15
Thread Starter
Fanatic Member
Re: [2008] Help with listview
That works great! Thanks a lot! =D
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
|