unit StringGrid_Lookup;
interface
// 2013 bummi
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TGetEditStyleEvent =
procedure(TSender: TObject; ACol, ARow: integer;
var EditStyle: TEditStyle)
of object;
TGetPickListItemsEvent =
procedure(TSender: TObject; ACol, ARow: integer;
Items: TStrings)
of Object;
TStringGrid =
Class(Grids.TStringGrid)
private
FOnGetEditStyle: TGetEditStyleEvent;
FOnGetPickListItems: TGetPickListItemsEvent;
Procedure GetPickListItems(ACol, ARow: integer; Items: TStrings);
public
function CreateEditor: TInplaceEdit;
override;
function GetEditStyle(ACol, ARow: integer): TEditStyle;
override;
published
Property OnGetPickListItems : TGetPickListItemsEvent
read FOnGetPickListItems
write FOnGetPickListItems;
Property OnGetEditStyle : TGetEditStyleEvent
read FOnGetEditStyle
write FOnGetEditStyle;
End;
TForm6 =
class(TForm)
StringGrid1: TStringGrid;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
procedure OnGetEditStyle(Sender: TObject; ACol, ARow: integer;
var EditStyle: TEditStyle);
procedure OnGetPickListItems(Sender: TObject; ACol, ARow: integer; Items: TStrings);
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
Procedure TForm6.OnGetEditStyle(Sender: TObject; ACol, ARow: integer;
var EditStyle: TEditStyle);
begin
if ACol = 2
then
EditStyle := esPickList;
end;
procedure TForm6.OnGetPickListItems(Sender: TObject; ACol, ARow: integer;
Items: TStrings);
begin
if ACol = 2
then
Items.Assign(Memo1.Lines);
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
StringGrid1.OnGetEditStyle := OnGetEditStyle;
StringGrid1.OnGetPickListItems := OnGetPickListItems;
end;
{ StringGrid }
function TStringGrid.CreateEditor: TInplaceEdit;
begin
Result := TInplaceEditList.Create(Self);
TInplaceEditList(Result).OnGetPickListItems := GetPickListItems;
TInplaceEditList(Result).DropDownRows := 8;
end;
function TStringGrid.GetEditStyle(ACol, ARow: integer): TEditStyle;
begin
Result := esSimple;
if Assigned(FOnGetEditStyle)
then
FOnGetEditStyle(Self, ACol, ARow, Result);
end;
procedure TStringGrid.GetPickListItems(ACol, ARow: integer; Items: TStrings);
begin
if Assigned(FOnGetPickListItems)
then
FOnGetPickListItems(Self, ACol, ARow, Items);
end;
end.