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. |
Re: Combobox in StringGrid flimmert
Hat denn keiner eine Idee :?:
Warum klappt das nicht :wall: :wall: :wall: :wall: |
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; |
Re: Combobox in StringGrid flimmert
Hab jetzt folgendes gemacht:
Die ComboBox wird direkt über die entsprechende Zelle gezeichnet:
Delphi-Quellcode:
Und wird in ihrem OnChange-Ereignis wieder ausgeblendet:
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;
Delphi-Quellcode:
Trotzdem thx @ Lannes für den Tipp :zwinker:
procedure TForm1.ComboBox1Change(Sender: TObject);
begin ComboBox1.visible := false; StringGrid1.Cells[aktCellX,aktCellY] := ComboBox1.Items[ComboBox1.itemindex]; ComboBox1.itemindex := 0; end; |
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