Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#6

AW: Komponente Stringgrid mit ComboBox

  Alt 13. Apr 2013, 22:22
Ich hätte einen anders gearteten Vorschlag,noch nicht als fertige Komponente ...
Hier wird statt des TInplaceedits ein TInplaceEditList erzeugt.

Delphi-Quellcode:
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.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat