Mega Code Archive

 
Categories / Delphi / Examples
 

Comboselect

THIS TOOK ME BLOODY AGES TO SORT OUT!!! The problem: to have a Combo Box scroll to the position of a specified item and have that item highlighted (ie to control which item is selected with code) SOLUTION: use the ItemIndex property. For example: var lineNum: Integer; first we populate the text in each Combo Box 'item' with a Printer font: (so the list contains all of them) with FontComboBox do begin Items := Printer.Fonts; ItemIndex := Items.IndexOf(Font.Name); end; and next we SELECT the item that says 'Times New Roman': lineNum := FontComboBox.Items.IndexOf('Times New Roman'); FontComboBox.ItemIndex := lineNum;