TListBox (Firemonkey) em tempo de execução
Olá Pessoal!
Estou tentando criar items customizados para um TListBox em tempo de execução.
Estou fazendo conforme abaixo:
Os item são criados e mostrados no listBox1 porém não consigo selecioná-lo...
Alguém teria um exemplo mais completo de como fazer isso? Desejo fazer um listBox cutomizado...
Estou tentando criar items customizados para um TListBox em tempo de execução.
Estou fazendo conforme abaixo:
var item : TListBoxItem; texto : TText; begin listBox1.HitTest := true; listBox1.Items.Add(''); item := listBox1.ListItems[listBox1.Items.Count-1]; item.HitTest := true; texto := TText.create(nil); texto.Text := 'Teste 01'; texto.HorzTextAlign := TTextAlign.taLeading; texto.VertTextAlign := TTextAlign.taLeading; texto.color := TAlphaColors.Black;; texto.parent := item; texto.Align := TAlignLayout.alClient; listBox1.Items.Add(''); item := listBox1.ListItems[listBox1.Items.Count-1]; item.HitTest := true; texto := TText.create(nil); texto.Text := 'Teste 02'; texto.HorzTextAlign := TTextAlign.taLeading; texto.VertTextAlign := TTextAlign.taLeading; texto.color := TAlphaColors.Black;; texto.parent := item; texto.Align := TAlignLayout.alClient;
Os item são criados e mostrados no listBox1 porém não consigo selecioná-lo...
Alguém teria um exemplo mais completo de como fazer isso? Desejo fazer um listBox cutomizado...
Carlos Phelippe
Curtidas 0
Respostas
Jerrivaldo
02/11/2014
Faz assim:
procedure TForm7.FormCreate(Sender: TObject);
var
ListBoxItem: TListBoxItem;
begin
with TListBoxItem.Create(ListBox1) do
begin
Size.Width := 388;
Size.Height := 50;
Size.PlatformDefault := False;
Text := 'Testando';
Visible := True;
Parent := ListBox1;
end;
end;
procedure TForm7.FormCreate(Sender: TObject);
var
ListBoxItem: TListBoxItem;
begin
with TListBoxItem.Create(ListBox1) do
begin
Size.Width := 388;
Size.Height := 50;
Size.PlatformDefault := False;
Text := 'Testando';
Visible := True;
Parent := ListBox1;
end;
end;
GOSTEI 0
Messias Galvão
02/11/2014
Só Complementando:
Var
ListBoxItem: TListBoxItem;
begin
ListBoxItem:= TListBoxItem.Create(ListBox1);
with ListBoxItem do
begin
Size.Width := 388;
Size.Height := 50;
Size.PlatformDefault := False;
Text := 'Banco do Brasil';
ItemData.Detail:= '0800 729 0722'; //Acrescenta um segundo item
ItemData.Accessory:= TListBoxItemData.TAccessory(3); //Efeito check
StyleLookup := 'listboxitembottomdetail'; // Listbox detalhado
Visible := True;
Parent := ListBox1;
end;
end;
Var
ListBoxItem: TListBoxItem;
begin
ListBoxItem:= TListBoxItem.Create(ListBox1);
with ListBoxItem do
begin
Size.Width := 388;
Size.Height := 50;
Size.PlatformDefault := False;
Text := 'Banco do Brasil';
ItemData.Detail:= '0800 729 0722'; //Acrescenta um segundo item
ItemData.Accessory:= TListBoxItemData.TAccessory(3); //Efeito check
StyleLookup := 'listboxitembottomdetail'; // Listbox detalhado
Visible := True;
Parent := ListBox1;
end;
end;
GOSTEI 0