我需要在选择了ListBox里的任意一项后执行某操作,请问如何判断选中了ListBox里的任意一项内容?代码该加在什么地方?我现在的代码如下:
var
  i: Integer;
begin
  for i:=0 to ListBox1.Items.Count-1 do
    if ListBox1.Items[i].checked then   //但这句老报错,为什么?
........
end;上面那句老报错,并且checked是手动输入的,并没有提示框出来选择?
请问怎么办?

解决方案 »

  1.   

    for i:=0 to ListBox1.Items.Count-1 do
        if ListBox1.Selected[i] then   
           ..........
      

  2.   

    var
      i: Integer;
    begin
      for i:=0 to ListBox1.Items.Count-1 do
        if ListBox1.Selected[i] then showmessage(ListBox1.Items.Strings[i]) ;
      

  3.   

    ListBox1.Items.IndexOf("aa")      得到Index
      ListBox1.Selected[i]              index为i的是否为选中
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      for i:=0 to ListBox1.Items.Count-1 do
        if ListBox1.Selected[i]then
        begin
        showmessage(ListBox1.Items.Strings[i]);
        end;end;