TableStyles missing from UserControl

G

Guest

I have a UserControl that contains a DataGrid control. The UserControl
exposes the TableStyles property of the constituent DataGrid to the outside
world

Public ReadOnly Property TableStyles() As
Windows.Forms.GridTableStylesCollection
Get
Return Me.Grid.TableStyles
End Get
End Property

When the UserControl is dropped onto a form the designer allows you to add
and modify the table styles through the table style editor just like it were
an ordinary DataGrid. and all of the code for the TableStyle,
CollumnHeaderStyles etc.. are added to the initialise component method of the
form as would be expected. However the line that should read

Me.NewDataGrid.TableStyles.AddRange(New
System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})

is not added to the code in initialise component. So, when you close the
table style editor the table style is not associated with the control as it
would be if it were an ordinary DataGrid. Adding the above line manually
after initialise component means that at runtime the table styles will apply,
but I cannot easily use the designer as I would like.

What am I missing please.
 
J

Jeffrey Tan[MSFT]

Hi Richard,

Thanks for your post.

Yes, I can reproduce out your issue.

Actually, we should apply DesignerSerializationVisibility.Content attribute
to this property, so that form designer will serialize the property for us.
Like this:
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property TableStyles() As
Windows.Forms.GridTableStylesCollection
Get
Return Me.DataGrid1.TableStyles
End Get
End Property

After applying this attribute, my sample works well.

Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Thank you Jeffrey. That seems to have done the trick.

Why is this different from simply adding a normal property to the control?
Public Property Foo() as String
Get

End get
Set(value as String)

End Set
End Property

The designer will store this property without doing anything special

Thanks

Ben
 
J

Jeffrey Tan[MSFT]

Hi,

I am not sure if you are Richard. Normally,
DesignerSerializationVisibility.Content indicates that each public,
non-hidden sub-property of the object will be serialized. While if we do
not specify this attribute explicitly, it will default be
DesignerSerializationVisibility.Visible, which means code generator only
produces code for the object.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top