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方法,如下:
-
type
-
TDBGrid = class(DBGrids.TDBGrid)
-
protected
-
procedure DoCopyToClipboard; override;
-
end;
-
-
procedure TDBGrid.DoCopyToClipboard;
-
var
-
s: String;
-
c: Integer;
-
begin
-
s := '';
-
for c := 0 to Columns.Count-1 do
-
s := s + #9 + Columns[c].field.AsString;
-
if s <> '' then Delete(s, 1, 1);
-
Clipboard.AsText := s;
-
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.