Recent

Author Topic: TListBox  (Read 6723 times)

marko

  • Guest
TListBox
« on: May 17, 2005, 06:47:12 pm »
How do I know which item is selected in TListBox, or which items are checked in TCheckListBox?

Please help.

matthijs

  • Hero Member
  • *****
  • Posts: 537
TListBox
« Reply #1 on: May 17, 2005, 07:52:27 pm »
An example of finding the selected item(s) of a TListBox:
Code: [Select]

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  if ListBox1.MultiSelect then begin
    Memo1.Clear;
    for I := 0 to pred(ListBox1.Items.Count) do begin
      if ListBox1.Selected[I] then Memo1.Lines.Add(ListBox1.Items[I]);
    end;
  end else begin
    if ListBox1.ItemIndex <> -1 then
      ShowMessage('Selected item: ' + ListBox1.Items[ListBox1.ItemIndex])
  end;
end;
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

matthijs

  • Hero Member
  • *****
  • Posts: 537
TListBox
« Reply #2 on: May 17, 2005, 07:59:07 pm »
Owh, forgot about the TCheckListBox. That goes exactly the same:
Code: [Select]

procedure TForm1.Button2Click(Sender: TObject);
var
  I: Integer;
begin
  Memo1.Clear;
  for I := 0 to pred(CheckListBox1.Items.Count) do begin
    if CheckListBox1.Checked[I] then Memo1.Lines.Add(CheckListBox1.Items[I]);
  end;
end;
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

marko

  • Guest
TListBox
« Reply #3 on: May 18, 2005, 08:38:54 am »
Thank you!

 

TinyPortal © 2005-2018