Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Combobox in StringGrid flimmert (https://www.delphipraxis.net/43070-combobox-stringgrid-flimmert.html)

gordon freeman 28. Mär 2005 17:03


Combobox in StringGrid flimmert
 
Hi Leute,

Ich zeige mit diesem Code von IBP eine Combobox in der letzten Spalte eines Stringgrids an. Wenn man jedoch die ComboBox nicht anklicjt sondern nur einmal in die Zelle klickt, flimmert die Box sehr. Woran liegt das und wie kann man es beheben?

Außerdem wird das Auswahlmenu der Einträgr nicht angezeigt, wenn man auf den Pfeil klickt! Woran kann das denn liegen :wall:

Hier der Code:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ComboBox1: TComboBox;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private-Deklarationen }
    procedure SetRect(Rect:TRect);
  public
    { Public-Deklarationen }
  end;

var
  aktCellX,aktCellY : integer;
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.SetRect(Rect:TRect);
var r:TRect;
begin
CopyRect(r,rect);
r.BottomRight := combobox1.Parent.ScreenToClient(StringGrid1.ClientToScreen(r.BottomRight));
r.TopLeft    := combobox1.Parent.ScreenToClient(StringGrid1.ClientToScreen(r.TopLeft));
ComboBox1.SetBounds(r.left,r.top,r.right-r.left,r.bottom-r.top);
ComboBox1.BringToFront;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
if (AktCellX = StringGrid1.ColCount-1) then
  begin
  setRect(Stringgrid1.CellRect(AktCellX,AktCellY));
  ComboBox1.Visible := true;
  end
else
  ComboBox1.Visible := false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.parent := StringGrid1;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
aktCellX := ACol;
aktCellY := ARow;
end;

end.

gordon freeman 29. Mär 2005 21:09

Re: Combobox in StringGrid flimmert
 
Hat denn keiner eine Idee :?:
Warum klappt das nicht :wall: :wall: :wall: :wall:

Lannes 30. Mär 2005 18:03

Re: Combobox in StringGrid flimmert
 
Hallo,

warum nutzt Du nicht den folgenden Tip?:
...eine Combobox als InPlace Editor in einem StringGrid verwenden?
Die Procedur ComboBox1Change entfernen.
Diese einfügen, damit man die Combobox mit Enter verlassen kann:
Delphi-Quellcode:
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_return then
   ActiveControl := StringGrid1;
end;

gordon freeman 31. Mär 2005 23:52

Re: Combobox in StringGrid flimmert
 
Hab jetzt folgendes gemacht:

Die ComboBox wird direkt über die entsprechende Zelle gezeichnet:
Delphi-Quellcode:
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  r: TRect;
begin
  ComboBox1.visible := true;
  r := Stringgrid1.CellRect(AktCellX, AktCEllY);
  Combobox1.SetBounds(r.Left + Stringgrid1.Left,
                      r.Top + Stringgrid1.Top,
                      r.Right - r.Left,
                      r.Bottom - r.Top);
end;
Und wird in ihrem OnChange-Ereignis wieder ausgeblendet:

Delphi-Quellcode:
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  ComboBox1.visible := false;
  StringGrid1.Cells[aktCellX,aktCellY] := ComboBox1.Items[ComboBox1.itemindex];
  ComboBox1.itemindex := 0;
end;
Trotzdem thx @ Lannes für den Tipp :zwinker:


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:36 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz