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

來源:互聯網
上載者:User

標籤:style   io   for   ar   div   line   c   app   

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;


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.