码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2017-12-23 01:09:25      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:and   hwnd   enable   lis   hand   sele   bookmark   全选   form   

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记录全选和反选拖动处理

标签:and   hwnd   enable   lis   hand   sele   bookmark   全选   form   

原文地址:http://www.cnblogs.com/jijm123/p/8087997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!