Multi select rows in a DBGrid using Shift (select as in the IE)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
property BM1: TBookmark read FBM1 Write SetBM1; property BM2: TBookmark read FBM2 Write SetBM2; procedure Markieren(Sender: TObject); function Shiftgedr: Boolean; procedure TForm1.Markieren(Sender: TObject); var Richtung: string; TempBM: TBookmark; begin with (Sender as TDBGRID).DataSource.Dataset do begin if (BOF and EOF) then Exit; DisableControls; try try GotoBookmark(BM1); case DBGrid1.DataSource.DataSet.CompareBookmarks(BM1, BM2) of -1: Richtung := 'Unten'; 1: Richtung := 'Oben'; 0: Richtung := 'Gleich'; end; TempBM := DBGrid1.DataSource.DataSet.GetBookmark; while DBGrid1.DataSource.DataSet.CompareBookmarks(BM2, TempBM) <> 0 do begin DBGrid1.SelectedRows.CurrentRowSelected := True; if Richtung = 'Unten' then Next else Prior; TempBM := DBGrid1.DataSource.DataSet.GetBookmark; end; finally FreeBookmark(tempbm); end; finally EnableControls; end; end; end; function TForm1.Shiftgedr: Boolean; var State: TKeyboardState; begin GetKeyboardState(State); Result := ((State[VK_SHIFT] and 128) <> 0); end; begin if not Shiftgedr then Merke1 := nil; if Merke1 = nil then Merke1 := DBGrid1.DataSource.DataSet.GetBookmark else Merke2 := DBGrid1.DataSource.DataSet.GetBookmark; if (Merke1 <> nil) and (Merke2 <> nil) then begin if Shiftgedr then begin Markieren(Sender); end; end; end; |