リストボックス(ListBox)の使い方
リストボックスは、ユーザにリストの中から項目を選ばせる時使用します。単に項目の表示用にも使用できます。
選択された項目番号を得るには
複数項目を選択させるには
例
var
i: Integer;
begin
if ListBox1.MultiSelect = False then
begin
MessageDlg('Selected = ' + IntToStr(ListBox1.ItemIndex)+ ' '+ListBox1.Items[ListBox1.ItemIndex],
mtInformation, [mbOK], 0);
end
else
begin
for i := 0 to ListBox1.SelCount do
begin
if ListBox1.Selected[i] = True then
MessageDlg('Selected = ' + IntToStr(i)+ ' '+ListBox1.Items[i],
mtInformation, [mbOK], 0);
end;
end;
end;
ItemsプロパティはTString型なので、Addメソッドで項目を追加できます。
例
var
str: string;
begin
str := InputBox('Item', 'Enter new item', '');
ListBox1.Items.Add(str);
end;
ItemsプロパティはTString型なので、Deleteメソッドで項目を削除できます。
例
ListBox1.Items.Delete(ListBox1.ItemIndex);