How to pass a collection of comboboxes to a Sub?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • axplains
    New Member
    • Feb 2010
    • 5

    How to pass a collection of comboboxes to a Sub?

    Hello everyone,
    I would like too generate a number of comboboxes at runtime and then pass them to a Sub, like this:
    Code:
    For i = 0 to maxnumber
      Dim cbo As New ComboBox()
      cbo.Name = "cbo" & i
      etc...
    Next
    etc...
    Myroutine("collection of comboboxes")
    
    Sub Myroutine(ByVal "collection of comboboxes")
      ...do something with the comboboxes...
    End Sub
    What is the correct syntax to use to pass the comboboxes collection to the Sub?

    Thank you.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    When you are making the comboboxes add them to a List<combobox> or an array combobox[] then send that array

    Comment

    • axplains
      New Member
      • Feb 2010
      • 5

      #3
      Tlhintoq, tThank you very much for you input, I have tried:

      Dim ComboList As List(Of Combobox) = Nothing
      For i etc...
      Dim cbo As New ComboBox()
      ComboList.Add(c bo)
      Next

      but I get an error "Object reference not set to an instance of an object".
      There is still something I am missing...

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Dim ComboList As List(Of Combobox) = Nothing
        Try setting your ComboList equal to a new List(Of Combobox) instead of setting it to nothing (null)

        Comment

        • axplains
          New Member
          • Feb 2010
          • 5

          #5
          Thanks a lot... that made it!

          Comment

          Working...