Button on DBGrid

I have below code to place a Button onto a DBGrid cell
with below code the button is visible just only
active row but i want to show buttons in every row
of the grid which has data  ( not empty )
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
    DataCol: Integer; Column: TColumn; State: TGridDrawState);
  var
  MRect : TRect ;
Begin
  If (Column.Index = 1) Then
  begin
    MRect := DBGrid1.CellRect(Column.Index,DBGrid1.Row);
    SpeedButton1.Parent := DBGrid1 ;
    SpeedButton1.Left := (MRect.Right - SpeedButton1.Width) ;
    SpeedButton1.Top := MRect.Top ;
    SpeedButton1.Height := (MRect.Bottom-MRect.Top);
  end;
end;
Thank You
0
Melissa
11/14/2014 5:13:48 AM
📁 embarcadero.delphi.general
📃 4258 articles.
⭐ 0 followers.

💬 4 Replies
👁️‍🗨️ 6313 Views


Trying to make you standard component fancy again? ;-)
I don't know if placing buttons on a grid is a good idea. 
Are you adding to all buttons the same click-event?
My way would be to add a extra 1st column to the grid.
Right mouse click on the grid, add all columns with the column 
editor and add an extra column. That extra column you can
place to the top to become the 1 column in the grid.
On the draw event of the grid you draw some borderlines 
in the 1st column cell in the same way a button is drawn. (some dark/light gray lines)
Then you use the onclick/onkeypress event of the grid to catch
the click on the 1st column by the user.
0
Robert
11/14/2014 11:27:31 AM
Melissa
>I have below code to place a Button onto a DBGrid cell
>with below code the button is visible just only
>active row but i want to show buttons in every row
>of the grid which has data ( not empty )
>
>procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
> DataCol: Integer; Column: TColumn; State: TGridDrawState);
> var
> MRect : TRect ;
>Begin
> If (Column.Index = 1) Then
> begin
> MRect := DBGrid1.CellRect(Column.Index,DBGrid1.Row);
> SpeedButton1.Parent := DBGrid1 ;
> SpeedButton1.Left := (MRect.Right - SpeedButton1.Width) ;
> SpeedButton1.Top := MRect.Top ;
> SpeedButton1.Height := (MRect.Bottom-MRect.Top);
> end;
>end;
Why are you trying to get the co-ordinates for the cell when they're passed into the event - just use Rect
For information DBGrid.Row is the active row.
Roy Lambert
0
Roy
11/14/2014 1:05:37 PM
Thank you Robert and Roy
If you have time please watch below video 
between 5,00 - 5,30  minutes, please check ITEMNO column
i did the same thing with Bitmap & works excellent 
but i wondered if i could do the same thing with speedbutton.
http://www.youtube.com/watch?v=aTkYs0dwXIo
0
Melissa
11/14/2014 5:26:14 PM
Melissa
>Thank you Robert and Roy
>If you have time please watch below video
>between 5,00 - 5,30 minutes, please check ITEMNO column
>i did the same thing with Bitmap & works excellent
>but i wondered if i could do the same thing with speedbutton.
Why do you want a TSpeedButton? If its so that you can respond to a click then why not respond to the mouse up event?
Roy Lambert
0
Roy
11/14/2014 5:59:36 PM
Reply: