Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 108,146 times

Contents

Related Categories

Combo Box - Adding items

Adding items

To add an item to a combo box during runtime, you can use the following syntax:

Combo1.AddItem Item, Index

where Item is a string containing the text to be displayed for that item. Index is an optional value to identify that item. You can only use a valid value. For example:

Combo1.AddItem "David", 4

is only valid if the list already has 4 items (remember the index starts from 0) If omitted, a default value is added. (0 is the first item on the list, 1 the second and so on). The following code adds three items to a combo box: David, Paul and Sarah.

Combo1.AddItem "David"
Combo1.AddItem "Paul"
Combo1.AddItem "Sarah"

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [70] Combo Box

    Posted by vincerihoo on 13 Apr 2007

    Try this:


    ComboBox1.Items.Add("Text")


    It's pretty flexible, you can put just about anything in there:


    ComboBox1.Items.Add("Text" & RichTextBox1.Text & someVaria...

  • Posted by Evic on 07 Mar 2004

    The .AddItem is to add items to the Combo Box at run time. This is normally the preferred way of doing this instead of doing it through the properties of the Combo Box.

    Usage:
    Combo1.AddItem "Stri...

  • Posted by HyperHacker on 11 Apr 2003

    Yeah, I was getting an error like "Invalid procedure call or argument" (Runtime error 5). It seems to work if I remove the index # (rather than Combo1.Additem "Blah" 2, just Combo1.Additem "Blah").

  • Error code

    Posted by mechuser2 on 06 Aug 2002

    Combo1.AddItem tells me that it's a wrong code.