当前位置:Gxlcms > 数据库问题 > Delphi实现DBGrid全选和反选功能

Delphi实现DBGrid全选和反选功能

时间:2021-07-01 10:21:17 帮助过:6人阅读

全选 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   

人气教程排行