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;
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)!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.