Menu

[r4761]: / branches / parsnip / Src / Main / CS.Components.StringGridEx.pas  Maximize  Restore  History

Download this file

113 lines (92 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2014, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* An extended TStringGrid component that replaces the grid'd standard in-place
* editor with the TInplaceEditList editor supplied in the Delphi VCL Grids
* unit.
*
* This implementation is derived from the tip "Replacing the TStringGrid's
* standard InplaceEditor" at http://delphi.longzu.net/viewthread.php?tid=47965
}
unit CS.Components.StringGridEx;
interface
uses
Classes,
Grids;
type
TGetEditStyleEvent = procedure (Sender: TObject; ACol, ARow: Integer;
var EditStyle: TEditStyle) of object;
TStringGridEx = class(TStringGrid)
strict private
var
fDropDownRowCount: Integer;
fOnEditButtonClick: TNotifyEvent;
fOnGetEditStyle: TGetEditStyleEvent;
fOnGetPickListItems: TOnGetPickListItems;
procedure SetDropDownRowCount(Value: Integer);
procedure SetOnEditButtonClick(Value: TNotifyEvent);
procedure SetOnGetPickListItems(Value: TOnGetPickListItems);
strict protected
function CreateEditor: TInplaceEdit; override;
function GetEditStyle(ACol, ARow: Integer): TEditStyle; override;
public
constructor Create(AOwner: TComponent); override;
published
property DropDownRowCount: Integer
read fDropDownRowCount write SetDropDownRowCount default 8;
property OnEditButtonClick: TNotifyEvent
read fOnEditButtonClick write SetOnEditButtonClick;
property OnGetEditStyle: TGetEditStyleEvent
read fOnGetEditStyle write fOnGetEditStyle;
property OnGetPickListItems: TOnGetPickListItems
read fOnGetPickListItems write SetOnGetPickListItems;
end;
implementation
{ TStringGridEx }
constructor TStringGridEx.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fDropDownRowCount := 8;
end;
function TStringGridEx.CreateEditor: TInplaceEdit;
begin
Result := TInplaceEditList.Create(self);
with TInplaceEditList(Result) do
begin
DropDownRows := fDropDownRowCount;
OnGetPickListItems := fOnGetPickListItems;
OnEditButtonClick := fOnEditButtonClick;
end;
end;
function TStringGridEx.GetEditStyle(ACol, ARow: Integer): TEditStyle;
begin
Result := esSimple;
if Assigned(fOnGetEditStyle)
then fOnGetEditStyle(Self, ACol, ARow, Result);
end;
procedure TStringGridEx.SetDropDownRowCount(Value: Integer);
begin
fDropDownRowCount := Value;
if Assigned(InplaceEditor) then
TInplaceEditList(InplaceEditor).DropDownRows := Value;
end;
procedure TStringGridEx.SetOnEditButtonClick(Value: TNotifyEvent);
begin
fOnEditButtonClick := Value;
if Assigned(InplaceEditor) then
TInplaceEditList(InplaceEditor).OnEditButtonClick := Value;
end;
procedure TStringGridEx.SetOnGetPickListItems(Value: TOnGetPickListItems);
begin
fOnGetPickListItems := Value;
if Assigned(InplaceEditor) then
TInplaceEditList(InplaceEditor).OnGetPickListitems := Value;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.