Lazarus DBGrid使用
Option:
1.dgMultiselect:可以选择多行;
2.dgRowselect:可以选择整行;
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.