views:

262

answers:

2

I have a weird problem, and I don't know if this is the default behaviour of .Net DataGridView inside a GroupBox/TabControl.

I've created a new WinForm project from scratch, and created a GroupBox(changed the text style). Like this:

alt text

Then, I've created a simple DataGridView, no font style at all, like this:

alt text

Then, in design mode, I dragged the DataGridView inside the GroupBox, and this sort of magic just happened:

alt text

My question is, can I disable this behaviour? Cause if I chage the DataGridView style outside the GroupBox and then drag it into, lost all the style.

Just for the record, this form has NO CODE at all.

Thanks in advance.

+2  A: 

What you are experiencing is known as Ambient Properties. In short it is a mechanism where a control will "inherit" some property values from its parent, if the properties are not explicitly assigned to. I don't know of a way to prevent the behavior, other than assigning the wished values to the properties.

Fredrik Mörk
A: 

Try putting a panel in the group box, then setting the font property of the panel. This way the DataGridView will inherit the properties of the panel. Much easier than setting every font property of the DataGridView.

Malcolm Worthy