2014年3月3日 星期一

delphi dbgrid 多選實現

procedure TForm3.dbgrd1CellClick(Column: TColumn);
//shift 多選
begin
     if (dgmultiselect in dbgrd1.options) then
        if getkeystate(vk_shift) < short(0) then
        begin
           getcursorpos(thispoint);
           while not dbgrd1.DataSource.DataSet.Eof and not dbgrd1.DataSource.DataSet.bof and
                 not (dbgrd1.datasource.dataset.fields[3].asstring =
                       thisfield) do
           begin
                 if thispoint.y > firstpoint.y then
                    dbgrd1.DataSource.DataSet.prior
                 else
                 dbgrd1.DataSource.DataSet.next;
                 dbgrd1.selectedrows.currentrowselected := true;
           end;
        end;
     getcursorpos(firstpoint);
     thisfield := dbgrd1.datasource.dataset.fields[3].asstring;
end;