dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Clear multiple listboxes

  1. #1
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238

    Clear multiple listboxes(Resolved)

    Hi everyone ..
    I have several listboxes on a form .. named list1 through list12
    They are NOT a control array.
    I need to clear them on one button click. Currently, I have it as
    List1.clear
    List2.clear
    ...
    List12.clear

    I would like to do this in a loop of some sort.
    I tried
    For i = 1 to 12
    List(i).clear
    Next
    But that errors out and a For Each Ctrl loop is not clearing the Listboxes.
    Any ideas?
    Thanks
    Michael
    Last edited by Hobbit K; December 21st, 2003 at 05:42 PM.

  2. #2
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Code:
    dim i as integer
    dim strName as string
    dim ctl as control
    
    for i = 1 to 12
       strName = "List" & i
       for each ctl in me.controls
            if ctl.name = strname then
                 ctl.clear
            end if
       next ctl
    next i
    Be nice to Harley riders...

  3. #3
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238
    TwoDogs ...
    Thanks ... I knew I was close. I was missing the ctrl.name part.

  4. #4
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Glad it worked...I didn't test it

    Actually, if those are the only listboxes on the form,
    then
    Code:
    for each ctl in me.controls
       if typeof ctl is listbox then
               ctl.clear
      end if
    next ctl
    will work just as well
    Be nice to Harley riders...

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)