Adding on to a ComboBox list


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 13 of 13

Thread: Adding on to a ComboBox list

  1. #1
    Join Date
    Apr 2005
    Posts
    20

    Question Adding on to a ComboBox list

    Does anyone know how to add on to an existing ComboBox list? Please help!!!!!

  2. #2
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    say the combobox is called cmbMyList

    you'd do:

    Code:
    cmbMyList.additem "My new item"
    This will add a new phrase "My new item" to the end of the list. But, it will not check to see if the item exists already, so you may get duplicates.

    If you want to add items in a loop:

    Code:
    for i = 0 to 9
    cmbMyList.additem i
    next i
    Easy

  3. #3
    Join Date
    Apr 2005
    Posts
    20

    Question Adding on to a Combo Box

    I know how to add items to the combo box with code. But the user of this program will not have access to the code and won't know how to code. I have a list of items in the combo box already but in the future the user may want to add on to the list. How can i do this????

  4. #4
    Join Date
    Apr 2005
    Location
    Pasig, Phil.
    Posts
    8
    Do you mean like when a user inputs information in a text box and it will automatically add in the combo box?

    ..well you can store it in a variable for example..

    Code:
    sample = text1.Value
    
    cmbMyList.additem=sample
    ...
    Last edited by surlaw; 05-13-2005 at 09:58 AM.

  5. #5
    Join Date
    Apr 2005
    Posts
    20

    Question adding on to a ComboBox list

    Hey Surlaw i tried out what you told me, but it only includes one entry on to the list and doesn't save it and it also replaces the first item in the database.
    Is there a way to fix that?

  6. #6
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    Sorry, misunderstood what you needed.

    You can add items and write them to a set of registry keys, then read them back when you load the software again. Or write/read them to/from a text file. Is this the sort of thing you'd like to do?

  7. #7
    Join Date
    Apr 2005
    Posts
    20

    Question Adding on to a ComboBox list

    No what you were saying before was the sort of thing i was asking. But the problem with the code is that it doesn't save to the list. By that i mean when you go back to the form you can't see the item added i the list of the combobox. I've tried the update method but it doesn't work. please help!!!!

  8. #8
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    At run-time or design-time?

    If it's at run-time, you'll need to write them to a file (or registry key) and then read them back next time you run.

    If it's at design-time, it should just work.

  9. #9
    Join Date
    Apr 2005
    Posts
    20

    Question Adding on to a ComboBox list

    It's during design time. Can't it read from a database rather than a file. The code i have at the moment is listing the added on items in the database but not in the combo box itself. When i can see the added on item when i add it but as soon as i close and open the program again, it's gone. Where should the initial combo box item list be coded? in form_load? What's the best place?

    PS. Thanks for helping me out!

  10. #10
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    If you're editing the box in design-time, when you close VB it should write the data back to the .frm file. It MAY be that you have a corrupt .frm file

    You should populate the combo box on form_activate as if you .hide a form and then .show it will refresh. If you do the update in form_load it won't update if you .hide then .show

  11. #11
    Join Date
    Apr 2005
    Posts
    20

    Question Adding on to a ComboBox list

    I put the initial combo list items in the form_activate section but it still doesn't work. Here is the code (just to make it easier for you to help me!):

    Private Sub cmdSetCancel_Click()
    Unload frmSetPrice
    End Sub

    Private Sub cmdSetOK_Click()

    deGetIntroduced.rsFeeConfig.Update
    cboSetType.Refresh
    Unload frmSetPrice

    End Sub

    Private Sub Form_Activate()
    With cboSetType
    .AddItem "Registration Fee"
    .AddItem "Monthly Fee"
    .AddItem "Meeting Fee"
    .Refresh
    End With


    End Sub

    Private Sub Form_Load()
    deGetIntroduced.rsFeeConfig.MoveLast
    deGetIntroduced.rsFeeConfig.AddNew


    frmSetPrice.Move (Screen.Width - frmSetPrice.Width) / 2, _
    (Screen.Height - frmSetPrice.Height) / 3
    End Sub



    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Dim sample As String
    sample = Text1.Text
    If KeyAscii = 13 Then
    cboSetType.AddItem sample
    cboSetType.Refresh
    cboSetType.SetFocus
    End If
    End Sub

  12. #12
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    items added at run time are not saved in the form (that is created when the application is compiled)
    To 'remember' added items, you should 1) add them to the database or 2) save them in the registry, whatever is more suitable for you. Then these items should be read and added to the list at the form Load event.

    BTW The form activate event is called every time the form gets the focus back, therefore it is not the place to configure elements (because can be called more than once) (well, sometimes it is used for that reason, and I do not like that practice, being careful to configure elements only once)
    BTW2 if you change the startupPosition of your form to CenterScreen, you do not have to move it in the form Load event
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  13. #13
    Join Date
    May 2005
    Posts
    1
    Hi everyone,

    Does anyone know how to activate the .AddItem method of the ComboBox and ListBox controls? My VBA editor does not recognize them.

    I am trying to add entries into the combo boxes and list boxes that are determined dynamically at run-time. But I am getting error when I try to use the .AddItem, .RemoveItem, and .Clear methods.

    Any tips are much appreciated.

    Thanks,
    Greg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center