Results 1 to 4 of 4

Thread: How can you loop through every listbox control on a form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    How can you loop through every listbox control on a form?

    Anyone know?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How can you loop through every listbox control on a form?

    Did you try something like this?
    VB Code:
    1. Option Explicit
    2. '
    3. '  ? TypeName(ctlall)
    4. '  ? ctlall.name
    5.  
    6.  
    7. Private Sub Form_Load()
    8.   Dim frm As Form
    9.   Dim ctlAll As Control
    10.     For Each frm In Forms
    11.       For Each ctlAll In frm
    12.         If TypeOf ctlAll Is ListBox Then
    13.           ctlAll.Enabled = False
    14.         End If
    15.       Next ctlAll
    16.     Next frm
    17. End Sub

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How can you loop through every listbox control on a form?

    The following sample may work for you:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim lst As Control, i%
    3.  
    4.     For Each lst In Me.Controls
    5.         If TypeOf lst Is ListBox Then
    6.             If lst.ListCount > 0 Then
    7.                 For i = 0 To lst.ListCount - 1
    8.                     'do something
    9.                 Next i
    10.             End If
    11.         End If
    12.     Next lst
    13.  
    14. End Sub

  4. #4
    Junior Member
    Join Date
    May 2005
    Location
    Jalgaon, Maharashtra, India
    Posts
    22

    Re: How can you loop through every listbox control on a form?

    your Problem is seems to be solved so mark it as solved

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