⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tntdbgridsex.pas

📁 TntExUpdate 是 流行的 TntUnicodeControls控件的扩展包.包括很难找到的 TntJVCL 也在里面. TntSysUtils2.pas/TntSysUtilsEx.pa
💻 PAS
字号:
unit TntDBGridsEx;

interface

uses
  Classes, DBGrids, TntDBGrids, TntVer;

type
  TTntColumnEx = class(TTntColumn)
  private
    FTabStop: Boolean;
  public
    constructor Create(Collection: TCollection); override;
  published
    property Tabstop: Boolean read FTabStop write FTabstop default true;
  end;

  TTntDBGridEx = class(TTntDBGrid)
  private
    FAbout: TAboutInfo;
    FOnBeforeInsert: TNotifyEvent;
    FOnBeforeDelete: TNotifyEvent;
  protected
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
    procedure SetColumnAttributes; override;
    function CreateColumns: TDBGridColumns; override;
  public
    function GetCurrentEditorText: WideString;
  published
    property About: TAboutInfo read FAbout write FAbout stored False;
    property OnBeforeDelete: TNotifyEvent read FOnBeforeDelete write FOnBeforeDelete;
    property OnBeforeInsert: TNotifyEvent read FOnBeforeInsert write FOnBeforeInsert;
  end;

implementation

uses
  TntDB, Windows;

{ TTntColumnEx }

constructor TTntColumnEx.Create(Collection: TCollection);
begin
  inherited;
  FTabStop := True;
end;

{ TTntDBGridEx }

function TTntDBGridEx.CreateColumns: TDBGridColumns;
begin
  Result := TTntDBGridColumns.Create(Self, TTntColumnEx);
end;

function TTntDBGridEx.GetCurrentEditorText: WideString;
begin
  if EditorMode then
    Result := (InplaceEditor as TTntDBGridInplaceEdit).Text
  else if SelectedIndex >= 0 then
    Result := GetWideText(Columns[SelectedIndex].Field);
end;

procedure TTntDBGridEx.KeyDown(var Key: Word; Shift: TShiftState);
begin
  if DataLink.Active then
  begin
    with Datalink.Dataset do
      if CanModify and (not ReadOnly) and (dgEditing in Options) then
      begin
        if Assigned(FOnBeforeInsert) then
        begin
          if (Key = VK_DOWN) and DataLink.EOF then
            FOnBeforeInsert(Self)
          else if (Key = VK_INSERT) then
            FOnBeforeInsert(Self);
        end;
        if Assigned(FOnBeforeDelete) and (Key = VK_DELETE) then
          FOnBeforeDelete(Self)
      end;
  end;
  inherited;
end;

procedure TTntDBGridEx.SetColumnAttributes;
var
  I: Integer;
begin
  inherited;
  for I := 0 to Columns.Count - 1 do
    with Columns[I] as TTntColumnEx do
      TabStops[I + IndicatorOffset] := TabStops[I + IndicatorOffset] and TabStop;

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -