micropathic Posted April 18, 2004 Posted April 18, 2004 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 Quote
Leaders Iceplug Posted April 18, 2004 Leaders Posted April 18, 2004 ListBox1.Items.Clear() ListBox2.Items.Clear() or use a For Each loop: For Each ctl In Me.Controls If TypeOf ctl Is ListBox Then :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
CattleRustler Posted April 19, 2004 Posted April 19, 2004 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 Quote mod2software Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.