whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

102 Visitors Online


 
...multi select rows in a DBGrid using Shift (select as in the IE)?
Autor: Michael Meyer
[ Print tip ]  

Tip Rating (11):  
     


//Folgendes muss eingebaut werden

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;

    //Im "OnMouseUP" des Grids folgenden Code einbauen
  
begin
    if not 
Shiftgedr then
      
Merke1 := nil;

    if Merke1 = nil then
      
Merke1 := DBGrid1.DataSource.DataSet.GetBookmark
    else
      
Merke2 := DBGrid1.DataSource.DataSet.GetBookmark;

    if (Merke1 <> niland (Merke2 <> nilthen 
    begin
      if 
Shiftgedr then 
      begin
        
Markieren(Sender);
      end;
    end;
  end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners