Multiselect Items in a List Box Sample
File: ...\Samples\Solution\Controls\Lists\Lmsel.scx
This sample shows how to manage multiple items selected in a list box. The form contains a list box with the MultiSelect property set to True (.T.). A combo box on the form contains all the items that are selected in the list box.
To process the multiple-selected items in a list box — to copy them to an array or incorporate them elsewhere in your application — loop through the list items and process the ones for which the Selected property is set to true (.T.). The following code is included in the Click event of the list box to display the selected items in a combo box and the number of selected items in a text box:
nNoSelected = 0 && variable to track number of selected items
THISFORM.cboSelected.Clear && clear the combo box
* main processing loop
FOR i = 1 TO THIS.ListCount
IF THIS.Selected(i)
nNoSelected = nNoSelected + 1
THISFORM.cboSelected.Additem (THIS.List(i))
ENDIF
ENDFOR
THISFORM.txtNoSelected.Value = nNoSelected
In the code associated with the Init event of this form, and in many places throughout this sample application, the character string values initially added to the list are first defined with a #DEFINE directive. Each of the defined constants ends with "_LOC". Microsoft internal localization tools extract these definitions so that the strings can be translated into whatever language the application is being localized in.
See Also
Tasks
Add Items Interactively to a List Box Sample
Display Multiple Columns in a List Box Sample
Display Pictures in a List Sample
Fill a List with Values from Different Sources Sample
Move Items Between List Boxes Sample
Open Multiple Files Interactively Sample
Treeview/Listbox Drag and Drop Sample