Default value for Component property

M

Mike

I have added some properties for my component and want to set the
default properties so they show the defaults when the component is
dropped on a form.

For example, should one property

Public Class WildcatComponent

Private Shared _ServerHost As String = "HDEV21"

<System.ComponentModel.DefaultValue("LocalHost")> _
Public Property ServerHost() As String
Get
Return _ServerHost
End Get
Set(ByVal value As String)
_ServerHost = value
End Set
End Property

End function

When I compile and add it to the toolbox and then in a test form
dropped the component, I am seeing a BLANK for this field. I am
expecting to see in the property editor

ServerHost: LocalHost

But its blank.

What am I missing here in setting the default.

--
 
M

Mike

Solved. Hmmm, its working now, I don't know why it didn't before.
but this time I am deleting the component first from the test form,
recompile the dll and drop it back in.

It works without the attribute. The initializer is all that is needed:

Private Shared _ServerHost As String = "LocalHost"
Public Property ServerHost() As String
Get
Return _ServerHost
End Get
Set(ByVal value As String)
_ServerHost = value
End Set
End Property

So whats the purpose of?

<System.ComponentModel.DefaultValue("LocalHost")>

thanks
 
M

Mike

Solved. Hmmm, its working now, I don't know why it didn't before.
but this time I am deleting the component first from the test form,
recompile the dll and drop it back in.

It works without the attribute. The initializer is all that is needed:

Private Shared _ServerHost As String = "LocalHost"
Public Property ServerHost() As String
Get
Return _ServerHost
End Get
Set(ByVal value As String)
_ServerHost = value
End Set
End Property

So whats the purpose of?

<System.ComponentModel.DefaultValue("LocalHost")>

thanks
 

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