Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preselect TListBox item at load? 1

Status
Not open for further replies.

bobbie100

Programmer
Aug 29, 2003
64
GB
When I open a form with a TListBox component I want to have the last used item already selected as though the user had just clicked the mouse on it.
How can I preselect a known item in a listbox when the form is first shown?
 
procedure TForm1.FormShow(Sender: TObject);
begin
//if you know the number
ListBox1.Selected[<the index number of the item you want selected>] := True;

//if you know the name
ListBox1.Selected[ListBox1.Items.IndexOf(<name of the item you want selected>)] := True;
end;


Shuesty
 
Many thanks Shuesty.
I had misread the help and thought Selected was a read only item for accessing the selection state of an item. Goes to show I need glasses (and a new brain)!

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top