Jonvy

导航

统计

Lazarus DBGrid使用

Option:

1.dgEditing:

  对单元内容进行编辑,需要点击鼠标2次,第1次选中单元,第2次进入编辑模式;

  为了避免要点2次才可编辑,可以设置dgAlwaysShowEditor=true,则可以直接编辑

2.dgMultiselect:可以选择多行;

3.dgRowselect:可以选择整行;

注:当dgRowselect=true时,则不能选择dgEditing选项 

Since DBGrid inherits a virtual method DoCopyToClipboard from its ultimate ancestor, TCustomGrid, you can solve this by subclassing: 

点击DBGrid行,选择整行数据进行Copy,需要重载TCustomDBGrid DoCopyToClipboard方法,如下:

  1. type
  2.   TDBGrid = class(DBGrids.TDBGrid)
  3.   protected
  4.     procedure DoCopyToClipboard; override;
  5.   end;
  6.  
  7. procedure TDBGrid.DoCopyToClipboard;
  8. var
  9.   s: String;
  10.   c: Integer;
  11. begin
  12.   s := '';
  13.   for c := 0 to Columns.Count-1 do
  14.     s := s + #9 + Columns[c].field.AsString;
  15.   if s <> '' then Delete(s, 1, 1);
  16.   Clipboard.AsText := s;
  17. end;

TDBGrid = class(DBGrids.TDBGrid),子类和父类同名,需要这样写。

Put the redeclaration of TDBGrid into the same unit in which you want to apply it, and put it in front of the first usage of a DBGrid instance. Or, if there are several places which you want to be handled in the same way, put it into a separate unit and mention this unit at the end of the uses list of all forms needing it. This way the compiler is "deceived", and he executes the modified DoCopyToClipbpoard rathter than the original one when CTRL+C is pressed.

 

posted on   不亮  阅读(415)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示