Solved

OnClick event doesn't work

Posted on 1998-08-23
3
336 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
ID: 1337474
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
ID: 1337475
Thanks.
Do you know why this is working with TPanel but not working with TStringGrid?
0
 
LVL 5

Author Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 111
proper way to parse text with delphi 7 123
Delphi cmd execution 6 62
How to define IfThen functions in one common unit? 4 54
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

825 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