Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 108,620 times

Contents

Related Categories

Combo Box - Removing items

Removing items

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

Combo1.RemoveItem Index

where Index is a integer representing the list index of the item to be removed. So if you use the previous example, David would have a list index of 0 (first item) , Paul's would be 1, and Sarah's 2. Note that if the combo is sorted, the list index will change as items are added. The following code removes the selected item, and the first item on the list.

' Remove the first item
Combo1.RemoveItem 0
' Remove the selected item
Combo1.RemoveItem Combo1.listindex

The listindex property returns the listindex of the currently selected item.

To remove all the items from a combo box simply use the following statement:

Combo1.Clear

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.