Delphi DBGrid记录全选和反选拖动处理

DBGrid1.DragMode   :=   dmManual;//留意这个设置不要变

procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);

procedure TForm18.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
case   Msg.message   of
          WM_LBUTTONDOWN:
          begin
              if   Msg.hwnd   =   DBGrid1.Handle   then
              begin
                  DBGrid1.Perform(Msg.message,   Msg.wParam,   Msg.lParam);
                  DBGrid1.DragMode   :=   dmAutomatic;
              end;
          end;
          WM_LBUTTONUP:   DBGrid1.DragMode   :=   dmManual;
      end;
end;

---------------------------------------------------------------

procedure TForm10.SpeedButton7Click(Sender: TObject);

//全选

begin
   with DBGrid1.datasource.dataset do
   begin
      First;
      while not dm.AQ_personal.EOF   do
      begin
         DBGrid1.SelectedRows.CurrentRowSelected := True;
         dm.AQ_personal.Next;
      end;
   end;
end;

procedure TForm10.SpeedButton8Click(Sender: TObject);//反选
var
i:integer;
SavePlace:TBookmarkList;
begin
DBGrid1.DataSource.DataSet.DisableControls;
for   i:=1   to   DBGrid1.DataSource.DataSet.RecordCount   do
begin
    DBGrid1.DataSource.DataSet.RecNo:=i;
    DBGrid1.SelectedRows.CurrentRowSelected:=Not DBGrid1.SelectedRows.CurrentRowSelected;
end;
SavePlace:=DBGrid1.SelectedRows;
//    DBGrid1.DataSource.DataSet.GotoBookmark(Pointer(SavePlace[0]));//将指针指向当前选择的第一条记录
DBgrid1.DataSource.DataSet.EnableControls;
end;


你可能感兴趣的:(Delphi DBGrid记录全选和反选拖动处理)