Results 1 to 2 of 2

Thread: delete listview item

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    delete listview item

    I use this code to remove the item in a ListView.

    Dim lvi As ListViewItem = DirectCast(ListView1.Items(1), ListViewItem) '/// where (1) is the index of the item
    ListView1.Items.Remove(lvi)

    But if there's only one item in the listview, I encounter an error.

    What code should I write?

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    the indexes of a listview in vb.net start at zero , so if you only have one item in the listview it will error on ListView1.Items(1) , because there isn't an item with an index of 1. you would need to specify 0 for the first item
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

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