Question

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 http://www.freeimagehosting.net/uploads/65f5f2762d.png

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

alt text http://www.freeimagehosting.net/uploads/09f55f951a.png

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

alt text http://www.freeimagehosting.net/uploads/d0334132f0.png

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top