Reputation: 14499
I could only find how to create a ListBoxItem
by clicking on the component -> Items Editor.
How can we create programmatically a ListBoxItem
using Firemonkey
?
Upvotes: 1
Views: 4788
Reputation: 371
I created ListBoxItem inside my ComboBox with some extra details:
var
LBoxItem : Array [1..50] of TListBoxItem;
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
begin
for i := 1 to 10 do
begin
LBoxItem[i] := TListBoxItem.Create(ComboBox2);
LBoxItem[i].Parent := ComboBox2;
LBoxItem[i].Text := 'LBox'+IntToStr(i);
LBoxItem[i].Font.Size := 18;
LBoxItem[i].StyledSettings := [];
LBoxItem[i].Height := 20;
end;
end;
Upvotes: 1
Reputation: 4878
Assuming that a ListBoxItem
is an item of an existing TListBox
component named ListBox1
, the item can be added like this:
ListBox1.Items.Add('an item name');
an alternative:
var
id: Integer;
. . .
ListBox1.Items.AddObject('an item name', TObject(id));
EDIT Notice that this approach has to be considered valid only if the underlying list is not sorted.
Upvotes: 3
Reputation: 613302
Simply create the list box item, and add it to the list box:
var
ListBoxItem: TListBoxItem;
begin
ListBoxItem := TListBoxItem.Create(ListBox1);
ListBoxItem.Text := 'foo';
// set other properties of the list box item at this point
ListBox1.AddObject(ListBoxItem);
end;
Upvotes: 11