Results 1 to 15 of 15

Thread: [RESOLVED] [2008] Help with listview

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Resolved [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.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2008] Help with listview

    Delete the row from the data source from which the listview was loaded, clear, and reload the listview.

  3. #3
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2008] Help with listview

    ListView1.Items.RemoveAt(index)

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Help with listview

    Noted....... But is there a way to be able to delete the selected index....???
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  5. #5
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Help with listview

    And if by any chance i had allowed MultiSelect...?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  7. #7
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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.

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Help with listview

    Quote 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.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    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?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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?

  12. #12
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2008] Help with listview

    Quote 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.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    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
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Help with listview

    try this:

    vb Code:
    1. For Each lvi As ListViewItem In ListView1.SelectedItems
    2.     IO.File.Delete(lvi.SubItems(1).Text & ".txt")
    3.     lvi.Remove()
    4. Next

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Help with listview

    That works great! Thanks a lot! =D
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width