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. Follow

4 Replies
6313 Views

Similar Articles

[PageSpeed] 33
Get it on Google Play
Get it on Apple App Store

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:

Web resources about - Button on DBGrid - embarcadero.delphi.general

Button - Wikipedia, the free encyclopedia
In modern clothing and fashion design , a button is a small fastener , now most commonly made of plastic , but also frequently of metal, wood ...

Nokia Asha 205 Features Facebook Button
A Facebook phone ? Not quite, but the new Nokia Asha 205 does feature a Facebook button, along the lines of the HTC ChaCha and HTC Salsa , which ...

Apple acknowledges that third-party home button repairs to iPhone 6 can brick the device
The Guardian reports that Apple has acknowledged growing complaints that third-party repairs to the Touch ID home button of an iPhone 6 can brick ...

Having your Home button replaced could brick your iPhone
... been left holding almost worthless phones because the latest update to iOS 9 permanently disables the handset if it detects that the Home button ...

Is this how Apple plans to remove the iPhone’s home button?
... for the future and some reports have suggested that the introduction of 3D Touch functionality in the iPhone 6s is a hint that the home button ...

Google Hates Those Fake “Download” Buttons As Much As You Do, Will Now Block Sites Using Them
... site out there that manages to exist through trickery. You go to it, looking for a specific file to download, and there’s a Big! Green! Button! ...

Google cracks down on shady, fake download buttons
... web browser, you’re now even safer from sneaky advertisers that try to get you to download their crummy software with fake download buttons. ...

Google keeps you safe from sneaky download buttons on the web
For years now, Google's been working hard to make the internet less dangerous. That's why the company has announced a new feature to strengthen ...

Google will warn users away from fake download buttons, social engineering
Google has announced its new Safe Browsing Initiative will now target deceptive download links and practices. Site designers that like playing ...

Google Will Shield You From Fake Download Buttons
Starting Wednesday, Google will block websites that serve up deceptive download buttons or fake embedded ads alerting users to malware. As of ...

Resources last updated: 2/23/2016 8:07:30 PM