请问怎样在wwdbgrid这控件或者dbgrid的一个单元格中加一个按钮呢,并且可以增加click事件处理的?

解决方案 »

  1.   

    DBGrid1.Columns[x]的ButtonStyle属性设为:cbsEllipsis DBGrid1的OnEditButtonClick事件响应那个小按钮的点击事件
      

  2.   

    我要求的那个按钮的Caption是可以写中文的,而且有hint的哦,可以吗?
      

  3.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if not (gdFocused in State) then Exit;
      Button1.Left:=TStringGrid(Sender).Left+Rect.Left+2;
      Button1.Top:=TStringGrid(Sender).Top+Rect.Top+2;
      Button1.Width:=Rect.Right-Rect.Left;
      Button1.Height:=Rect.Bottom-Rect.Top;
      Button1.Parent:=self;
    end;
      

  4.   

    这么懒吗?自己改改嘛procedure TForm1.Button1Click(Sender: TObject);
    var
      i, j: integer;
    begin
      for i:=1 to 3 do
        for j:=1 to 4 do
        begin
          StringGrid1.Cells[j, i]:=Format('(%d, %d)', [i, j]);
        end;
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      btn: TButton;
    begin
      if ACol<>2 then Exit;
      if TStringGrid(Sender).Cells[ACol, ARow]='' then Exit;
      btn:=TButton.Create(nil);
      btn.Caption:=TStringGrid(Sender).Cells[ACol, ARow];
      btn.Left:=TStringGrid(Sender).Left+Rect.Left+2;
      btn.Top:=TStringGrid(Sender).Top+Rect.Top+2;
      btn.Width:=Rect.Right-Rect.Left;
      btn.Height:=Rect.Bottom-Rect.Top;
      btn.Parent:=self;
    end;end.
      

  5.   

    我要在wwdbgrid中创建哦,如果按照上面的方法的话,那么当改变一列的显示宽度的时候就会产生好多个button了
      

  6.   

    是哦,我也是这么想的,就是不知道怎样吧一个想按钮的图片放到wwdbgrid中,最好刚好位置为一个单元格,
    而wwdbgrid好像没有单击事件,只有mosedown事件哦
      

  7.   

    mousedown不就可以嘛,有什么区别吗?
      

  8.   

    DBGRID中带有一个属性就可以实现呀!加一个Column,后将buttonstyle中设置为cbsEllipsis就有按扭了!