Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Object and Array

Object and Array

Scheduled Pinned Locked Moved Visual Basic
questiondata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roger6897
    wrote on last edited by
    #1

    A class was created, and objects added to a listbox to form an arraylist. Ojects were added to arraylist as in Dim item As items For Each item In form1.Arraylistlist Me.Listbox1.Items.Add(item) Next How can I delete an object from the arraylist when displayed in Listbox1?

    L 1 Reply Last reply
    0
    • R roger6897

      A class was created, and objects added to a listbox to form an arraylist. Ojects were added to arraylist as in Dim item As items For Each item In form1.Arraylistlist Me.Listbox1.Items.Add(item) Next How can I delete an object from the arraylist when displayed in Listbox1?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, you can add and remove items to/from any collection using the appropriate methods, see documentation. However, when you try to modify a collection while you are enumerating it (as in a for each), you will get an exception. There are many remedies: - don't use for each in this case, use a for or a while loop - create a Clone of the list for the enumeration - use a temporary collection to remember which items will have to be deleted afterwards :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups