Board index » cppbuilder » TStringGrid = Bad Parent???
Jason W. Hinson
![]() CBuilder Developer |
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 |