Property ... what am I doing wrong?

S

shapper

Hello,

Let me explain it better. What I need is to make something like:

Dim mc as MyControl
mc.Value = "Hello"

This would create a MyControl instance and would set the TextBox.Text
= "Hello"

Then, I would need retrieve its value through the property on, for
example, a MyControl event:

Sub mc_CustomEvent(...) Handles mc.CustomEvent

Dim s as string

s = mc.Value

End Sub

Inside my custom control I have the property defined as follows:

Private _Value As String
Public Property Value() As String
Get
Return tbInput.Text
End Get
Set(ByVal value As String)
_Value = value
End Set
End Property ' Value

And the TextBox is defined as follows:

Private Sub tbInput_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles tbInput.Init
tbInput.Text = Me.Value
End Sub

Both set and get are not working.

If I use the property as follows:

Private _Value As String
Public Property Value() As String
Get
Return _Value
End Get
Set(ByVal value As String)
_Value = value
End Set
End Property ' Value

I am at least able to define the TextBox value.

What am I doing wrong?

Thanks,

Miguel
 
R

Roland Dick

Hi shapper,
Inside my custom control I have the property defined as follows:

Private _Value As String
Public Property Value() As String
Get
Return tbInput.Text
End Get
Set(ByVal value As String)
_Value = value
End Set
End Property ' Value

And the TextBox is defined as follows:

Private Sub tbInput_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles tbInput.Init
tbInput.Text = Me.Value
End Sub

Both set and get are not working.

I think what's happening is that you're setting Value from the code
using your control after it has been initialized - so _Value has the
proper string, but nothing writes that string into tbInput.Text.

Unless you need it for something else, get rid of _Value, and read
from/write to tbInput.Text in your Get and Set accessor.

Hope this helps,

Roland
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top