我怎么样在TRzStringGrid某一指定的单元格中无逢嵌入一个TComboBox??

解决方案 »

  1.   


    注意TComboBox的left,top,visible属性就是。。也可以使用API MoveWindow进行combo的移动 
    或者 直接 .left, .top这样 也可以就是跟着移动之类的了。。比较繁 不过不会复杂
      

  2.   

    代码片断
    在窗体上添置TCombobox;
    在初始化的时候
    cbokm.Visible := False;
    然后在SelectCell事件里边添加类似代码。
    procedure TFrmJPReg.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    var  R: TRect;
    org: TPoint;
    begin
       if (ACol = 1) and (ARow >= StringGrid1.FixedRows) then
       begin
          StringGrid1.Perform(WM_CANCELMODE, 0, 0);
          R := StringGrid1.CellRect(ACol, ARow);
          org := Self.ScreenToClient(self.ClientToScreen(R.TopLeft));
          with edtSUM do
          begin
             SetBounds(org.X+StringGrid1.Left, org.Y+ StringGrid1.Top, R.Right-R.Left, Height);
             Text := StringGrid1.Cells[ACol, ARow];
             Show;
             BringToFront;
             SetFocus;
          end;
       end
       else if (ACol = 2) and (ARow >= StringGrid1.FixedRows) then
       begin
          StringGrid1.Perform(WM_CANCELMODE, 0, 0);
          R := StringGrid1.CellRect(ACol, ARow);
          org := Self.ScreenToClient(self.ClientToScreen(R.TopLeft));
          with cbokm do
          begin
             SetBounds(org.X+StringGrid1.Left, org.Y+ StringGrid1.Top, R.Right-R.Left, Height);
             ItemIndex := Items.IndexOf(StringGrid1.Cells[ACol, ARow]);
             Show;
             BringToFront;
             SetFocus;
             DroppedDown := true;
          end;
       end
       else if (ACol = 3) and (ARow >= StringGrid1.FixedRows) then
       begin
          StringGrid1.Perform(WM_CANCELMODE, 0, 0);
          R := StringGrid1.CellRect(ACol, ARow);
          org := Self.ScreenToClient(self.ClientToScreen(R.TopLeft));
          with edtJE do
          begin
             SetBounds(org.X+StringGrid1.Left, org.Y+ StringGrid1.Top, R.Right-R.Left, Height);
             EdtJE.Text := StringGrid1.Cells[ACol, ARow];
             Show;
             BringToFront;
             SetFocus;
          end;
       end
       else if (ACol = 4) and (ARow >= StringGrid1.FixedRows) then
       begin
          StringGrid1.Perform(WM_CANCELMODE, 0, 0);
          R := StringGrid1.CellRect(ACol, ARow);
          org := Self.ScreenToClient(self.ClientToScreen(R.TopLeft));
          with cboDIr do
          begin
             SetBounds(org.X+StringGrid1.Left, org.Y+ StringGrid1.Top, R.Right-R.Left, Height);
             ItemIndex := Items.IndexOf(StringGrid1.Cells[ACol, ARow]);
             Show;
             BringToFront;
             SetFocus;
             DroppedDown := true;
          end;
       end
    end;
      

  3.   

    为了怕你不给分,还是把代码弄简单点
    代码片断
    在窗体上添置TCombobox;
    在初始化的时候
    cbokm.Visible := False;
    然后在SelectCell事件里边添加类似代码。
       if (ACol = 2) and (ARow >= StringGrid1.FixedRows) then
       begin
          StringGrid1.Perform(WM_CANCELMODE, 0, 0);
          R := StringGrid1.CellRect(ACol, ARow);
          org := Self.ScreenToClient(self.ClientToScreen(R.TopLeft));
          with cbokm do
          begin
             SetBounds(org.X+StringGrid1.Left, org.Y+ StringGrid1.Top, R.Right-R.Left, Height);
             ItemIndex := Items.IndexOf(StringGrid1.Cells[ACol, ARow]);
             Show;
             BringToFront;
             SetFocus;
             DroppedDown := true;
          end;
       end
      

  4.   

    stringgrid的cell有一个rect,获取这个rect,然后将combobox控件显示在对应的rect上就可以了,没有多大的难度吧!
      

  5.   

    combobox有rect这个属性吗我怎么没有找到