StringGridに、TCustomEditから継承した任意のコンポーネントや、ComboBoxを貼るにはどうしたらよいでしょう?
こんな感じでどうでしょう
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
SetStr:string;
Header:LongInt;
begin
SetStr := StringGrid1.Cells[ACol,ARow];
if (gdFocused in State) then begin
SetWindowPos(ComboBox1.Handle,0,
Rect.Left+StringGrid1.Left+1,
Rect.Top+StringGrid1.Top+1,
Rect.Right-Rect.Left+2,
Rect.Bottom-Rect.Top+2,
SWP_NOZORDER or SWP_SHOWWINDOW);
ComboBox1.Text := SetStr;
ComboBox1.Show;
Exit;
end;
if ComboBox1.Visible then
ComboBox1.Visible := False;
StringGrid1.Canvas.FillRect(Rect);
if ARow = 0 then
Header := (DT_CENTER or DT_VCENTER or DT_SINGLELINE)
else
Header := (DT_SINGLELINE or DT_VCENTER or DT_LEFT);
DrawText(StringGrid1.Canvas.Handle,
PChar(SetStr),Length(SetStr),
Rect,Header)
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ComboBox1.Visible := False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.DefaultRowHeight := ComboBox1.Height-StringGrid1.GridLineWidth;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
With StringGrid1 do begin
Cells[Col,Row] := ComboBox1.Text;
end;
end;
なんとかうまく出来そうです。
ありがとうございました。
ツイート | ![]() |