Solved

OnClick event doesn't work

Posted on 1998-08-23
3
331 Views
Last Modified: 2010-04-04
when I place a TButton on TStringGrid like this:

Button1.Parent:=StringGrid1;

then, the OnClick Event of the Button doesn't work.
With SpeedButtons it works fine.
Any ideas?
0
Comment
Question by:ronit051397
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 50 total points
Comment Utility
Hi,
This is a simple solution. You could inherit the TButton and add the ControlStyle line to the decendant constructor if you want:

procedure TForm1.MyButtonClick(Sender: TObject);
begin
  ShowMessage( 'I work!' );
end;

procedure TForm1.FormCreate(Sender: TObject);
  ...
  with TButton.Create( Self ) do begin
    ControlStyle := ControlStyle + [csClickEvents]; // add this!
    Parent := StringGrid1;
    with StringGrid1.CellRect( 1, 1 ) do SetBounds( Left, Top, Right - Left + 1, Bottom - Top + 1 );
    Caption := 'My button';
    OnClick := MyButtonClick;
  end;
end;

/// John
0
 
LVL 5

Author Comment

by:ronit051397
Comment Utility
Thanks.
Do you know why this is working with TPanel but not working with TStringGrid?
0
 
LVL 5

Author Comment

by:ronit051397
Comment Utility
For some reason, this is not working with TUpDown Component. Do you know why?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now