Delphi DBGrid記錄全選和反選拖動處理

DBGrid1.DragMode   :=   dmManual;//留意這個設置不要變指針

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

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;it

---------------------------------------------------------------io

procedure TForm10.SpeedButton7Click(Sender: TObject);form

//全選List

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;grid

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;margin

相關文章
相關標籤/搜索