AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Komponente Stringgrid mit ComboBox

Ein Thema von Ginko · begonnen am 13. Apr 2013 · letzter Beitrag vom 15. Apr 2013
Antwort Antwort
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#1

AW: Komponente Stringgrid mit ComboBox

  Alt 13. Apr 2013, 21:12
Delphi-Quellcode:
unit UComboGrid;

type
  TComboGrid = class(TStringGrid)
  public
    constructor Create(AOwner: TComponent; TopPos: Integer); reintroduce;
  end;
Dein Konstruktor ist nicht in Ordnung, denn ab der Klasse TComponent ist der Konstruktor virtuell; und das aus gutem Grund.
Nur wenn der Konstruktor die gleiche Bauart (Signatur) hat wie von TComponent kann die dynamische Erzeugung von Komponenten aus einer DFM-Datei funktionieren.
Der Parameter TopPos ist zudem völlig überflüssig, weil Top := TopPos .

Falls du ein Stringgrid mit erweiterten Fähigkeiten willst dann schau dir mal das XStringGrid an.
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

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

AW: Komponente Stringgrid mit ComboBox

  Alt 13. Apr 2013, 21: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
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:08 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz