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

Delphi实现DBGrid全选和反选功能

时间:2017-12-23 01:00:56      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:sts   增加   proc   false   set   class   isa   roc   gpo   

    Delphi实现Dbgrid全选和反选、清除全选的功能,不管是在Delphi下,还是在WEB开发中,这种功能都是很实用的,是进行数据批量操作的基础。本模块就是实现了为Delphi的DBGrid数据列表增加全选内容、清除全选的功能,很实用了,代码内容如下:

//全选
procedure TFrameCustSelector.ToolButton1Click(Sender: TObject);
var
  OldCurrent: TBookmark;
begin
  OldCurrent := DBGrid1.DataSource.DataSet.Bookmark;
  DBGrid1.DataSource.DataSet.DisableControls;
  DBGrid1.DataSource.DataSet.First ;
  while not DBGrid1.DataSource.DataSet.Eof do begin
    DBGrid1.SelectedRows.CurrentRowSelected := true;
    DBGrid1.DataSource.DataSet.Next;
  end;
  DBGrid1.DataSource.DataSet.GotoBookmark(OldCurrent);
  DBGrid1.DataSource.DataSet.EnableControls;
end;
//清除全选
procedure TFrameCustSelector.ToolButton2Click(Sender: TObject);
var
  OldCurrent: TBookmark;
begin
  OldCurrent := DBGrid1.DataSource.DataSet.Bookmark;
  DBGrid1.DataSource.DataSet.DisableControls;
  DBGrid1.DataSource.DataSet.First ;
  while not DBGrid1.DataSource.DataSet.Eof do begin
    DBGrid1.SelectedRows.CurrentRowSelected := False;
    DBGrid1.DataSource.DataSet.Next;
  end;
  DBGrid1.DataSource.DataSet.GotoBookmark(OldCurrent);
  DBGrid1.DataSource.DataSet.EnableControls;
end;
//反选
procedure TFrameCustSelector.ToolButton3Click(Sender: TObject);
var
OldCurrent: TBookmark;
begin
  OldCurrent := DBGrid1.DataSource.DataSet.Bookmark;
  DBGrid1.DataSource.DataSet.DisableControls;
  DBGrid1.DataSource.DataSet.First ;
  while not DBGrid1.DataSource.DataSet.Eof do begin
    DBGrid1.SelectedRows.CurrentRowSelected := not DBGrid1.SelectedRows.CurrentRowSelected;
    DBGrid1.DataSource.DataSet.Next;
  end;
  DBGrid1.DataSource.DataSet.GotoBookmark(OldCurrent);
  DBGrid1.DataSource.DataSet.EnableControls;
end;

 

Delphi实现DBGrid全选和反选功能

标签:sts   增加   proc   false   set   class   isa   roc   gpo   

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

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