SelCount(ListBoxなど)


SelCountプロパティは ListBoxコントロールなどで選択されている項目の総数を返します.Delphiでも同じく「SelCount」プロパティで調べることが可能です。

■ TListBoxの SelCountの使用例
  procedure TForm1.Button2Click(Sender: TObject);
  var
    ix  : integer;
  begin
    {一つでも選択されているかどうか}
    if  ListBox1.SelCount = 0 then  begin
      {選択されていない}
      MessageDlg('項目を選択してください!',mtWarning,[mbOk],0);
      Exit;
    end;
    for ix  :=  ListBox1.Items.Count - 1  downto  0 do  begin
      {選択されているか?}
      if  ListBox1.Selected[ix] then  begin
        {メモに追加}
        Memo1.Lines.Add(ListBox1.Items[ix]);
        {リストボックスから削除}
        ListBox1.Items.Delete(ix);
      end;
    end;
  end;