How to programmatically add a new ComboBox to a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aaa

    How to programmatically add a new ComboBox to a form

    Hello to all,

    In an application under VB6, I need to fill some ComboBoxes with data.
    However, I don't know in advance how many ComboBoxes I will need. I could
    of course create many (maybe 15 or 20) and only use those that I need.

    However, I would rather like to programmaticall y create and them to my form.
    How can this be achieved? Also, is there a generic method that could be
    used with other objects? (For example, programmaticall y create new forms.)

    Thank you in advance for you help.

    John H. Dewbert
    john_h_dewbert@ hotmail.com


  • Adam Parkin

    #2
    Re: How to programmaticall y add a new ComboBox to a form

    Create a combobox on your form in design view. Assign the index property
    the value 0 to turn this into a control array. You can then create new
    instances of the combobox in this array on the fly with something like:

    Load cboArray(cboArr ay.Ubound + 1)

    Then to refer to this new combobox use cboArray(cboArr ay.Ubound)

    For example to create a column of 10 comboboxes, each with 5 pixels between
    them:

    Dim ix As Integer

    For ix = 1 To 10
    Load cboArray(cboArr ay.Ubound + 1) ' load next combobox

    ' work with the new combobox
    With cboArray(cboArr ay.Ubound)
    .Top = cboArray(cboArr ay.Ubound - 1).Top + _
    cboArray(cboArr ay.Ubound - 1).Height + _
    5 * Screen.TwipsPer PixelY

    .Visible = True ' make sure you set this, as otherwise the new
    comboboxes might not be visible
    End With
    Next ix

    Don't know about doing forms on the fly though.

    Hope this helps,

    Adam


    "aaa" <john_h_dewbert @hotmail.com> wrote in message
    news:4KCmc.4403 5$3Q4.1066740@n ews20.bellgloba l.com...[color=blue]
    > Hello to all,
    >
    > In an application under VB6, I need to fill some ComboBoxes with data.
    > However, I don't know in advance how many ComboBoxes I will need. I could
    > of course create many (maybe 15 or 20) and only use those that I need.
    >
    > However, I would rather like to programmaticall y create and them to my[/color]
    form.[color=blue]
    > How can this be achieved? Also, is there a generic method that could be
    > used with other objects? (For example, programmaticall y create new[/color]
    forms.)[color=blue]
    >
    > Thank you in advance for you help.
    >
    > John H. Dewbert
    > john_h_dewbert@ hotmail.com
    >
    >[/color]


    Comment

    • John H. Dewbert

      #3
      Re: How to programmaticall y add a new ComboBox to a form

      Thank you for the tip, I think it will solve most of my problems!

      John.


      "Adam Parkin" <skdfja@dfaslk. com> a écrit dans le message de
      news:UeEmc.2501 7$LA4.16360@edt nps84...[color=blue]
      > Create a combobox on your form in design view. Assign the index property
      > the value 0 to turn this into a control array. You can then create new
      > instances of the combobox in this array on the fly with something like:[/color]


      Comment

      Working...