请问当listbox的mutiselected属性为true时,当我选多项时,怎么样才能记录下来它的选择的起始位置和末位置?

解决方案 »

  1.   

    通常通过循环来处理listbox的多选项  例:
    procedure TForm1.Button1Click(Sender: TObject);
    Var
      i:integer;
    begin
      for i := 0 to (ListBox1.Items.Count - 1) do 
      begin
        if ListBox1.Selected[i] then 
        showmessage(listbox1.Items.Strings[i]);
      end;end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,first,last : integer;
    begin
      firstid := false;
      lastid := false;
      //起始
      for i := 0 to listbox1.Items.Count -1 do
      begin
        if listbox1.Selected[i] then
        begin
           first := i;
           break;
        end;
      end;
      //结束
      for i := listbox1.Items.Count -1 downto 0 do
      begin
        if listbox1.Selected[i] then
        begin
           last := i;
           break;
        end;
      end;
      showmessage(inttostr(first)+' '+inttostr(last));
    end;
      

  3.   

    sorry ,应该是这样procedure TForm1.Button1Click(Sender: TObject);
    var
      i,first,last : integer;
    begin
      //起始
      for i := 0 to listbox1.Items.Count -1 do
      begin
        if listbox1.Selected[i] then
        begin
           first := i;
           break;
        end;
      end;
      //结束
      for i := listbox1.Items.Count -1 downto 0 do
      begin
        if listbox1.Selected[i] then
        begin
           last := i;
           break;
        end;
      end;
      showmessage(inttostr(first)+' '+inttostr(last));
    end;
      

  4.   

    多谢,挺简单的,Thank you!