Question and Answer Database FAQ2696D.txt Listbox selected property Category :VCL Platform :All Product :All 32 bit Question: When I try to set the selected property of a ListBox component, I receive an exception that the Index is out of bounds. How do I get around this? Answer: The selected property should only be used with ListBox components that have the MultiSelect property set to true. If you are working with a ListBox that has the MultiSelect property set to false, use the ItemIndex property to select the item. Example: procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items.Add('1'); ListBox1.Items.Add('2'); {This will fail on a single selection ListBox} // ListBox1.Selected[1] := true; ListBox1.ItemIndex := 1; {This is ok} end; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99