delphi如何在stringgrid中加入combobox

来源:百度知道 编辑:UC知道 时间:2024/06/04 00:33:04
procedure TForm1.sss(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
combobox1.Visible := TRUE;
combobox1.Left := stringgrid2.CellRect(ACol, ARow).Left;
combobox1.Top := stringgrid2.CellRect(ACol, ARow).Top;
combobox1.Parent := self;
combobox1.Width := stringgrid2.CellRect(ACol, ARow).Right-stringgrid2.CellRect(ACol, ARow).Left;
colTmp:=ACol;
rowTmp:=ARow;
end;

执行这句话后,combobox总是在stringgrid表格之外,而不是在cell里面。这句哪里有问题

试试下面的方法行不行
var
TempRect: TRect;

TempRect:=Column.Grid.CellRect(Column.Grid.Col,Column.Grid.Row);
dtpDTimeP_temp.Width:=Column.Width;
dtpDTimeP_temp.Height:=20;
dtpDTimeP_temp.Left:= TempRect.TopLeft.X+ Column.Grid.Left;
dtpDTimeP_temp.Top:=TempRect.TopLeft.Y+Column.Grid.Top;
dtpDTimeP_temp.Visible:=true;
dtpDTimeP_temp.SetFocus;

这是我在dbgrid中画了个datetimepicker的代码完美嵌入

推荐用AdvStringgrid ,Stringgrid的升级版,里面可以很轻松的加下拉框,单选框等。

我家里机器的环境上有用到AdvStringgrid的项目,具体的可以pm我咯。。

procedure TForm1.StringGrid1Click(Sender: TObject);
var
comtest : TComboBox;
begin
StringGrid1.RowCount := 3;
StringGrid1.ColCount := 3;
StringGrid1.Rows[0].Text := 'testcombox';
comtest := TComboBox.Create(self.StringGrid1);
comtest.Left := StringGrid1.CellRect(1, 1).Left;
comtest.Top := StringGrid1.CellRect(1, 1).Top;
comtest.Parent := self.Strin