borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Coma and dot separator for decimal numbers) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Changing the contents of a combobox
Poster Message
iliekater
Level: Master

Registered: 04-02-2005
Posts: 125

icon Changing the contents of a combobox

I can't change the contents of a combobox . I use what is specified in the help files :
MyComboBox.List(0, 0) = "Center"
MyComboBox.List(1, 0) = "Center"
MyComboBox.List(2, 0) = "Under"

but nothing ... Let me specify here that I am trying to modify the existing contents of the combobox (not to add or delete ones) .

[Edited by iliekater on 16-10-2007 at 02:24 PM GMT]

16-10-2007 at 10:24 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 910
icon Re: Changing the contents of a combobox

Hello. I tried the code below on a form with a combobox and two command buttons, and it works. Maybe it's useful to you (of course, you can even try with only three or few more items).

Option Explicit

Private Sub Form_Load()
    Dim i As Integer
    ' initialize the combo with some empty items
    With Me.Combo1
        For i = 0 To 25
            .AddItem "", i
        Next i
    End With
    ' load the first names' set
    Command1_Click
End Sub

Private Sub Command1_Click()
    ' load the male names list
    With Me.Combo1
        .List(0) = "robin"
        .List(1) = "romeo"
        .List(2) = "tristan"
        .List(3) = "stitch"
        .List(4) = "bernie"
        .List(5) = "charles"
        .List(6) = "harry"
        .List(7) = "jack"
        .List(8) = "rhett"
        .List(9) = "clark"
        .List(10) = "paris"
        .List(11) = "fred"
        .List(12) = "clyde"
        .List(13) = "ulysses"
        .List(14) = "tramp"
        .List(15) = "mickey"
        .List(16) = "shrek"
        .List(17) = "alladin"
        .List(18) = "roger"
        .List(19) = "donald"
        .List(20) = "syd"
        .List(21) = "john"
        .List(22) = "aristotele"
        .List(23) = "lancelot"
        .List(24) = "aragorn"
        .List(25) = "brad"
    End With
End Sub

Private Sub Command2_Click()
    ' load the female names list
    With Me.Combo1
        .List(0) = "marian"
        .List(1) = "juliet"
        .List(2) = "isolde"
        .List(3) = "lilo"
        .List(4) = "bianca"
        .List(5) = "camilla"
        .List(6) = "hermione"
        .List(7) = "rose"
        .List(8) = "scarlet"
        .List(9) = "lois"
        .List(10) = "helen"
        .List(11) = "ginger"
        .List(12) = "bonnie"
        .List(13) = "penelope"
        .List(14) = "lilly"
        .List(15) = "minnie"
        .List(16) = "fiona"
        .List(17) = "jasmine"
        .List(18) = "jessica"
        .List(19) = "daisy"
        .List(20) = "nancy"
        .List(21) = "yoko"
        .List(22) = "jacqueline"
        .List(23) = "guinevere"
        .List(24) = "arwen"
        .List(25) = "angelina"
    End With
End Sub
Try setting a male name, then click the second button to show the correspondant female name.
Notice also that all the names in the list have changed.

Hope it helps.

____________________________
Real Programmer can count up to 1024 on his fingers

26-10-2007 at 05:44 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Changing the contents of a combobox
Next Topic (Coma and dot separator for decimal numbers) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder