delphi实现DBGrid全选和反选功能,可使用TPopupMenu在DBGrid里实现右键功能
Delphi实现Dbgrid全选和反选、清除全选的功能,代码内容如下:
//全选
procedure TForm1.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 TForm1.ToolButton2Click(Sender: TObject);
var
OldCurrent: TBookmark;
begin
OldCurrent := DBGrid1.DataSource.DataSet.Bookmark;
DBGrid1.DataSource.DataSet.DisableControls;
DBGrid1.DataSource.DataSet.First ;
while not DB