Grab Listbox’s Multiselect content and play in a Memo on the same line

Asked

Viewed 938 times

2

I need to play the content with one or more selections from TListbox in a TMemo.

I activated the Multiselect for True,

I’m using:

ListBox.Items[ListBox.ItemIndex] 

Only with a selection it normal list, I need it to list if I mark your lines display: select1, select2

Currently only displays selection1 regardless of how many I choose

1 answer

2


You must make a loop and go through the entire list looking for the selected values, passing 1 to 1.

procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
begin
  for i := 0 to ListBox1.Items.Count -1 do
  begin
    if (ListBox1.Selected[i]) then
    begin
      if (Memo1.Text = '') then
        Memo1.Text := ListBox1.Items[i]
      else
        Memo1.Text := Memo1.Text + ', ' + ListBox1.Items[i];
    end;
  end;
end;

I await the Feedback.

  • I quickly changed only the order to Richmemo1.Text := Richmemo1.Text + Listboxorigem.Items[i] + ','; then I do an if not to display the comma in the last selected, but it worked thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.