Results 1 to 5 of 5

Thread: how to copy a ComboBox content to another

  1. #1

    Thread Starter
    Lively Member Edilson's Avatar
    Join Date
    Aug 2000
    Location
    Orlando
    Posts
    81

    Talking

    i need to combobox with the same content in the same form ....
    what's the best way to do this ???

  2. #2
    Guest
    Code:
    For I = 0 To Combo1.ListCount - 1
        Combo2.AddItem Combo1.List(I)
    Next I

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    How about this?
    Code:
    Private Sub ReplicateCombo(src As ComboBox, dest As ComboBox)
        dest.Clear
        For i = 0 To src.ListCount - 1
            dest.AddItem src.List(i)
            dest.ItemData(i) = src.ItemData(i)
        Next i
    End Sub
    Private Sub Command1_Click()
        ReplicateCombo Combo1, Combo2
    End Sub
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    Private Sub Form_Load()
    Dim i%
    For i = 1 To 10
    Combo1.AddItem Str(i)
    Next

    For i = 0 To Combo1.ListCount - 1
    Combo2.AddItem Combo1.List(i)
    Next
    End Sub

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    Code:
    Private Sub Form_Load()
    
    'will fill as many combos as there are on a form with the same content
    'mycontrol = control and increment is increment for forms
    '
    Dim ctlMyControl As Control
    Dim intIncrement As Integer
    Dim intCre As Integer
    '
        For intIncrement = 0 To Forms.Count - 1
            For Each ctlMyControl In Forms(intIncrement).Controls
              If TypeOf ctlMyControl Is ComboBox Then
       For intCre = 1 To 10
            With ctlMyControl
             .AddItem intCre * Int(Rnd * 199)
        End With
         Next intCre
              End If
        
            Next ctlMyControl
    '
                Next intIncrement
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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