procedure TfrmuMulCond.sgCondSelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var R:TRect;
begin
  . 
  . 
  .
  R:=sgCond.CellRect(ACol,ARow);
  sgCond.SetFocus ;  sgCond.DefaultRowHeight:=cbxGX.Height;  if ACol=COL_MATH then     
  begin
    cbxGX.Left:=sgCond.Left+R.Left+1;
    cbxGX.Top:=sgCond.Top+R.Top+1;
    cbxGX.Width:=R.Right-R.Left;
    cbxGX.Visible :=True;
    cbxGX.Items.Clear ;
  end;
end;
请问为什么在进行一系列操作(如点击,上下移动[move]各行位置)后,会出现combobox框的位置与stringgrid的cell位置不在一个位置上,combobox经常在cell的下面一点点,看起来很不好看!!!哪位知道是什么原因导致的???

解决方案 »

  1.   

    我試了下, 會出現你說的問題, 但我改了下
    sgCond.DefaultRowHeight:=cbxGX.Height; ->cbxGX.Height := StringGrid1.DefaultRowHeight;就沒事了!!
      

  2.   

    列出代码,完成基本的功能
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    stringgrid1.defaultrowheight:=combobox2.Height;
    combobox2.Visible:=false;
    end;procedure TForm1.ComboBox2Exit(Sender: TObject);
    begin
    stringgrid1.cells[stringgrid1.col,stringgrid1.row]:=combobox2.items[combobox2.itemindex];
    combobox2.Visible:=false;
    stringgrid1.setfocus;end;procedure TForm1.ComboBox2Change(Sender: TObject);
    begin
    stringgrid1.cells[stringgrid1.col,stringgrid1.row]:=combobox2.items[combobox2.itemindex];
    combobox2.Visible:=false;
    stringgrid1.setfocus;end;procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    var
     R:TRect;
     Num:integer;
    begin
    if (acol<>2) then
     canselect:=false
    else 
    if acol=5  then
    begin
    r:=stringgrid1.cellrect(acol,arow);
    r.left:=r.left+stringgrid1.left;
    r.right:=r.right+stringgrid1.left;
    r.top:=r.top+stringgrid1.top;
    r.bottom:=r.bottom+stringgrid1.top;
    combobox2.left:=r.left+1;
    combobox2.top:=r.top+1;
    combobox2.width:=(r.right+1)-r.left;
    combobox2.height:=(r.bottom+1)-r.top;
    combobox2.Visible:=true;
    combobox2.setfocus;canselect:=true;
    end;
    end;