Einzelnen Beitrag anzeigen

Ginko

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

AW: Komponente Stringgrid mit ComboBox

  Alt 15. Apr 2013, 11:37
Läuft auch unter D7 problemlos, dass der Beispielcode nur bei Column eine "Combobox" anzeigt hast Du gesehen?
 if ACol = 2 then .....
Ja, ich habe alle Felder durchprobiert, dann muss es wohl was mit meiner Delphi Insatllation zu tun haben, obwohl ich es einmal unter Virtualbox und einmal in einer echten XP-Installation versucht hatte.

Naja ich werd dann wohl mit der Version unten vorlieb nehmene müssen und auf die flexiblere Laufzeiterstellung verzichten...
Aber was gut ist, die Version läuft auch unter Lazarus.
Trotzdem Danke für die Antworten.

Delphi-Quellcode:
{ StringGrid mit ComboBox }

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  CRect:TRect;
begin
  if(ACol=1)then
  begin
    CRect:=StringGrid1.CellRect(ACol, ARow);
    inc(CRect.Left, StringGrid1.Left+2);
    inc(CRect.Right, StringGrid1.Left+2);
    inc(CRect.Top, StringGrid1.Top+2);
    inc(CRect.Bottom, StringGrid1.Top+2);
    ComboBox1.BoundsRect:=CRect;
    ComboBox1.Visible:=true;
    ComboBox1.ItemIndex:=integer(StringGrid1.Objects[ACol, ARow])-1;
  end
    else ComboBox1.Visible:=false;
end;


procedure TForm1.StringGrid1Exit(Sender: TObject);
begin
  if not(ActiveControl=ComboBox1)then
  begin
    ComboBox1.Visible:=false;
    StringGrid1.Selection:= TGridRect(Rect(-1, -1, -1, -1));
  end;
end;


procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
  if not(ActiveControl = StringGrid1)then
  begin
    ComboBox1.Visible:= false;
    StringGrid1.Selection:= TGridRect(Rect(-1, -1, -1, -1));
  end;
end;


procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
var
  GRect:TGridRect;
begin
  ComboBox1.Visible:= false;
  GRect:= StringGrid1.Selection;
  if(GRect.Left = 0) and (GRect.Right = 0)then
    begin
    inc(GRect.Left, 1);
    inc(GRect.Right, 1);
    end;
  StringGrid1.Selection:=GRect;
end;
  Mit Zitat antworten Zitat