设置DBGrid的Options的dgMultiSelect:=True 
这样就可以一次选多个行了,请问怎么样遍历出我选中行,各个字段的值呢?

解决方案 »

  1.   

    帮助中的例子var
      i, j: Integer;
      s: string;
    begin
      if DBGrid1.SelectedRows.Count>0 then
        with DBGrid1.DataSource.DataSet do
          for i:=0 to DBGrid1.SelectedRows.Count-1 do
          begin
            GotoBook(pointer(DBGrid1.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;