指尖风暴 Typhon Finger

  • 首页
  • 公告
  • 新闻
  • 技术
  • 教学
  • 收藏
  • 下载
  • 博客
  • 商城
  • 购物车
  • 帐户
指尖风暴 TyphonFinger
日常技术笔记和技术输出~~~
  1. 首页
  2. 技术信息
  3. 正文

Delphi实现DBGrid全选和反选功能

2019-02-08 339点热度 0人点赞 0条评论

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;
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2019-02-08

指尖风暴

TyphonFinger

打赏 点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论

COPYRIGHT © 2022 指尖风暴 Typhon Finger. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang