Delphi实现DBGrid全选和反选功能
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;
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。