请教各位大虾,,,好何把combox添加到stringgrid里呢。

解决方案 »

  1.   

    http://www.2ccc.com/article.asp?articleid=3066
      

  2.   


    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    var
      i,m,n,j:Integer;
    begin
      i:=self.StringGrid1.TopRow-1;
      n:=0;
      if ARow=0 then
        n:=0
      else
      begin
        for j:=i to arow-1 do
          n:=n+self.StringGrid1.RowHeights[j];
      end;
      self.ComboBox1.Top:=self.StringGrid1.Top+n+(arow-i+1)*self.StringGrid1.GridLineWidth;
      m:=0;
      if ACol=0 then
        m:=0
      else
      begin
        for i:=0 to acol-1 do
          m:=m+self.StringGrid1.ColWidths[i];
      end;
      self.ComboBox1.Left:=self.StringGrid1.Left+m+(acol+1)*self.StringGrid1.GridLineWidth;
      self.ComboBox1.Visible:=true;
      self.ComboBox1.Width:=self.StringGrid1.ColWidths[ACol];
      self.ComboBox1.Height:=self.StringGrid1.RowHeights[ARow];
    end;
      

  3.   

    控制ComboBox1在StringGrid上显示的位置,来达到你说的那种效果
      

  4.   

    以前做过
    方法是放一个combobox 
    再放一个 stringgrid 并设置选择一行,不是单个的距形
    在stringgrid 里的选择行事件里
    得到位置,再按位置放上combobox
      

  5.   

    procedure TForm1.StrGridClick(Sender: TObject);
    var
      vRect: TRect;
    begin
      if (StrGrid.Row>0) and (StrGrid.Row<StrGrid.RowCount) then
      begin
        if (StrGrid.Col=2) then
        begin
          vRect := StrGrid.CellRect(StrGrid.Col,StrGrid.Row);
          ComboBox1.Top := StrGrid.Top + vRect.Top+1;
          ComboBox1.Width := vRect.Right-vRect.Left;
          ComboBox1.Height := vRect.Bottom - vRect.Top ;
          ComboBox1.Left := StrGrid.left + vRect.Left + 1;
          ComboBox1.Text := strGrid.Cells[StrGrid.Col,StrGrid.Row];
          ComboBox1.Visible := true;
          ComboBox1.SetFocus;
        end;
        if (StrGrid.Col=1) then
        begin
          vRect := StrGrid.CellRect(StrGrid.Col,StrGrid.Row);
          ComboBox1.Top := StrGrid.Top + vRect.Top+1;
          ComboBox1.Width := vRect.Right-vRect.Left;
          ComboBox1.Height := vRect.Bottom - vRect.Top ;
          ComboBox1.Left := StrGrid.left + vRect.Left + 1;
          ComboBox1.Text := strGrid.Cells[StrGrid.Col,StrGrid.Row];
          ComboBox1.Visible := true;
          ComboBox1.SetFocus;
        end;
      end else
        ComboBox1.Visible := false;
    end;