我选择了DBGridEh中的若个行,但怎样取得DBGridEh中选择的多行数据..

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i, j: Integer;
      s: string;
    begin
      if DBGridEh1.SelectedRows.Count>0 then
        with DBGridEh1.DataSource.DataSet do
          for i:=0 to DBGrid1Eh.SelectedRows.Count-1 do
          begin
            GotoBook(pointer(DBGridEh1.SelectedRows.Items[i]));
            for j := 0 to FieldCount-1 do
            begin          if (j>0) then s:=s+', ';
              s:=s+Fields[j].AsString;
            end;
            Listbox1.Items.Add(s);
            s:= '';
          end;
    end;
      

  2.   

    书签可以记录你选过的记录:
    if DBGrideh1.SelectedRows.Count > 0 then
      begin
        sum := 0;
        with DBGrideh1.DataSource.DataSet do
        begin
          for i := 0 to DBGrid1.SelectedRows.Count-1 do
          begin
            GotoBook(Pointer(DBGrid1.SelectedRows.Items[i]));
             ... 取数据操作...
           end;
        end;
        end
    end;
      

  3.   

    哦,謝謝樓上兩位,不過還有點美中不足,如果能用到eh的隨意選擇就更好了,比如只選取下面field2和field3列,3,4,5行,就讀出這3行數據。field1    field2    field3    field4
    1           001      aaa        bbb
    2           002    aaa       bbb
    3           選中   選中      bbb
    4           選中     選中       bbb
    5           選中     選中       bbb
    6           006      aaa        bbb
      

  4.   

    以下是Ehlib中TDBGridEh.SelectedRows的帮助文件,TDBGridEh.SelectedRows
    Specifies a set of books for all the records in the dataset that correspond to rows selected in the grid.property SelectedRows: TBookListEh;DescriptionUse the properties and methods of the TBookListEh object returned by SelectedRows to • Determine the number of rows in the grid that are selected.
    • Determine whether the current record in the dataset is selected.
    • Determine whether a particular record in the dataset is selected.
    • Delete all selected rows from the dataset.SelectedRows is only meaningful when the Options property includes dgRowSelect. SelectedRows can only identify a single row unless the Options property includes dgMultiSelect.EhLib Software