procedure TForm1.ListView1Click(Sender: TObject);
begin
    showmessage(inttostr(listview1.Selected.Index));
end;

解决方案 »

  1.   

    直接listview1.ItemIndex 就可以了。
      

  2.   

    procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      i:integer;
    begin
      i:=ListBox1.ItemAtPos(TPoint(X, Y), True));
    end;robinhunter(深空) 的方法不行
    除非
      for i:= 0 to ListBox1.Count - 1 do
      begin
        if ListBox1.Selected[i] then
        begin
          ...
          break;
        end;
      end;
    而且前提是ListBox只能为单选!
      

  3.   

    procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      i:integer;
    begin
      i:=ListBox1.ItemAtPos(TPoint(X, Y), True));
    end;robinhunter(深空) 的方法不行
    除非
      for i:= 0 to ListBox1.Count - 1 do
      begin
        if ListBox1.Selected[i] then
        begin
          ...
          break;
        end;
      end;
    而且前提是ListBox只能为单选!
      

  4.   

    procedure TForm1.ListView1Click(Sender: TObject);
    begin
      if listview1.selected<>nil then
        showmessage(inttostr(listview1.Selected.Index));
    end;
      

  5.   

    procedure TForm1.ListView1Click(Sender: TObject);
    begin
      if listview1.selected<>nil then
        showmessage(inttostr(listview1.Selected.Index));
    end;
      

  6.   

    procedure TForm1.ListView1Click(Sender: TObject);
    begin
      if listview1.selected<>nil then
        showmessage(inttostr(listview1.Selected.Index));
    end;
      

  7.   

    cb_1.click事件
      if listview1.Selected.Index>=0 then
        showmessage(inttostr(listview1.Selected.Index))
      else
        showmessage('未选择');
    当未选时执行上述语句出错,未出现‘未选择’这个对话框