Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I am trying to clear 24 listbox on my form. They are all named like this: listbox1, listbox2, listbox3, etc.

 

My question is, how can I loop through all of them and clear them. Here's what I had come up with that didn't seem to work:

 

 

       Dim dirlistbox As string
       Dim i As Integer

          For i = 1 To 24
         
            dirlistbox = dirlistbox(i)
            dirlistbox.items.clear

          Next

  • Leaders
Posted

ListBox1.Items.Clear()

ListBox2.Items.Clear()

 

or use a For Each loop:

For Each ctl In Me.Controls

If TypeOf ctl Is ListBox Then

:)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

yes, for-each is your friend and proves the uselessness of control arrays - they are already in collections which are arrays...

 

dim ctl as Control

For Each ctl In Me.Controls
   If TypeOf ctl Is ListBox Then
       clt.items.clear
   end if
next

mod2software

Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...