Einzelnen Beitrag anzeigen

Ginko

Registriert seit: 30. Aug 2008
208 Beiträge
 
FreePascal / Lazarus
 
#10

AW: Komponente Stringgrid mit ComboBox

  Alt 14. Apr 2013, 13:59
So hab die Options mal entsprechend gesetzt aber leider erscheint keine ComboBox wenn ich die Zellen anklicke. Das ganze Compiliert ohne probleme in Delphi 7 Pers.

Delphi-Quellcode:
unit Unit1;

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;

  TForm1 = class(TForm)
    Memo1: TMemo;
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(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
  Form1: TForm1;

implementation

{$R *.dfm}

Procedure TForm1.OnGetEditStyle(Sender: TObject; ACol, ARow: integer;
  var EditStyle: TEditStyle);
begin
  if ACol = 2 then
    EditStyle := esPickList;
end;

procedure TForm1.OnGetPickListItems(Sender: TObject; ACol, ARow: integer;
  Items: TStrings);
begin
  if ACol = 2 then
    Items.Assign(Memo1.Lines);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.OnGetEditStyle := OnGetEditStyle;
  StringGrid1.OnGetPickListItems := OnGetPickListItems;
end;

//Änderung gegenüber Orignal
procedure TForm1.FormShow(Sender: TObject);
begin
  StringGrid1.Options := StringGrid1.Options + [goTabs] + [goEditing] + [goAlwaysShowEditor];
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.

Geändert von Ginko (14. Apr 2013 um 14:12 Uhr)
  Mit Zitat antworten Zitat