1. 程式人生 > >Delphi實現DBGrid全選和反選功能

Delphi實現DBGrid全選和反選功能

web log con ont procedure del div 操作 var

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全選和反選功能