# List Box & Combo Box Tutorial

It is important to note that list boxes and combo boxes differ in only two respects:

1. All of a list box's events, styles, and messages are prefixed with LB. A combo box's, on the other hand, all begin with CB.
2. There are three types of combo boxes the most common of which is CBS_DROPDOWN.

Unlike the preceding tutorials, I am not going to show the code here because of it length. The code can be found in the ListBoxSample.cpp file in the samples directory. Instead I will refer to code snipits.

Typically you add elements to a list box or combo box like this:

>     lb->addString( buf );

You acess the selected string using like this:

>     lb->getSelectedString();

You can get all the elements in the listbox like this:

>     char buf[MAX_ELEMENTS];
>     buf[0] = 0;
>     for ( int i = 0; i < lb->getNumberOfItems(); i++ )
>     {
>       strcat( buf, lb->getString( i ) );
>       strcat( buf, "\n" );
>     }

If your lisbox is not a pointer you can access its elements using array notation, for example:

>     char buf[MAX_ELEMENTS];
>     buf[0] = 0;
>     for ( int i = 0; i < lb->getNumberOfItems(); i++ )
>     {
>       strcat( buf, lb[i] );
>       strcat( buf, "\n" );
>     }