Board index » cppbuilder » TStringGrid = Bad Parent???

TStringGrid = Bad Parent???


2003-11-13 07:31:44 AM
cppbuilder51
I've seen these sorts of questions asked, but haven't found real
answers...
Try this: Place a TStringGrid on a form. Then, try to place a Button
(or checkbox or whatever) on the TStringGrid. The StringGrid won't
accept the component, rather the component's parent is always set to the
form (or whatever the StringGrid's parent is).
Okay, so let's be stubborn and place the button on the StringGrid
programmatically by adding
Button1->Parent = StringGrid1;
Button1->Top = 5;
Button1->Left = 5;
to the form's constructor. That works!
Ah, but now try assigning an OnClick event to the button:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Application->MessageBox("It worked!","Message",MB_OK);
}
//---------------------------------------------------------------------------
You'll find that once you assign the button's parent as the StringGrid,
the OnClick event is ignored! Fortunately, it seems that MouseDown and
MouseUp still work, but I'm confused as to why OnClick is ignored.
So, my questions:
(1) Why can't you place a component on a TStringGrid in the IDE?
(2) If you place a component on a TStringGrid programmatically, why is
OnClick then ignored?
Thanks!
-Jason
 
 

Re:TStringGrid = Bad Parent???

"Jason W. Hinson" < XXXX@XXXXX.COM >wrote in message
Quote
Try this: Place a TStringGrid on a form. Then, try to place a Button
(or checkbox or whatever) on the TStringGrid. The StringGrid
won't accept the component, rather the component's parent is always
set to the form (or whatever the StringGrid's parent is).
As well it should. The StringGrid is not set up to accept components being
dropped onto it. That is a setting that has to be explitically enabled in
the component's source code. That is not the case with grids.
Quote
Ah, but now try assigning an OnClick event to the button:
<snip>
You'll find that once you assign the button's parent as the
StringGrid, the OnClick event is ignored!
Correct, because the grid intecepts all mouse and keyboard messages for its
own purposes. Grids are not designed to host child controls other than its
own InplaceEdit, so they have no concept of proper message handling when it
comes to placing your own custom controls inside the grid.
Quote
(1) Why can't you place a component on a TStringGrid in the IDE?
Because Grid components are not designed to allow such behavior by enabling
the necessary settings.
Quote
(2) If you place a component on a TStringGrid programmatically, why is
OnClick then ignored?
Because the grid is intercepting the messages before any child controls can
get to them. They assume that any messages received are meant only for
either themselves itself or their InplaceEditor, nothing else.
Gambit
 

Re:TStringGrid = Bad Parent???

Jason W. Hinson wrote:
Quote
(2) If you place a component on a TStringGrid programmatically,
why is OnClick then ignored?
Maybe this will help:
www.bridgespublishing.com/articles/articleindex.php
Check the April 2002 issue for "Even more string grids part 1."
 

{smallsort}

Re:TStringGrid = Bad Parent???

Thanks to both Gambit and Fishface for the replies!
-Jason