1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure ComboBox1Change(Sender: TObject);
procedure StringGrid1TopLeftChanged(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.DefaultRowHeight := ComboBox1.Height;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
R: TRect;
begin
if (TStringGrid(Sender).Cells[2,aRow] <> '') And
(aCol = 3) and
(aRow >= StringGrid1.FixedRows) and
(gdFocused in State) THEN
with ComboBox1 do
begin
BringToFront;
CopyRect(R, Rect);
R.TopLeft := Form1.ScreenToClient(
StringGrid1.ClientToScreen(R.TopLeft));
R.BottomRight := Form1.ScreenToClient(
StringGrid1.ClientToScreen(R.BottomRight));
SetBounds(R.Left, R.Top, R.Right-R.Left, R.Bottom-R.Top);
end;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
with StringGrid1 do
Cells[Col, Row] := ComboBox1.Text;
end;
procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
var
R: TRect;
begin
with StringGrid1 do
CopyRect(R, CellRect(Col, Row));
with ComboBox1 do
begin
Visible := False;
R.TopLeft := Form1.ScreenToClient(
StringGrid1.ClientToScreen(R.TopLeft));
R.BottomRight := Form1.ScreenToClient(
StringGrid1.ClientToScreen(R.BottomRight));
SetBounds(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
end;
with StringGrid1 do
if (TopRow <= Row) and (TopRow + VisibleRowCount > Row) then
ComboBox1.Show;
end;
end. |
Partager