property: can it be an object?

T

tmaster

Can I pass a listview to another form using a property definition like this?

Public Class frmToDoDetail
Inherits System.Windows.Forms.Form

Private m_lvwTD As ListView

Public Property lvwTD() As ListView
Get
lvwTD = m_lvwTD
End Get
Set(ByVal Value As ListView)
m_lvwTD = lvwTD
End Set
End Property

.... try to access the listview using m_lvwTD or lvwTD doesn't work?
------------------------------

Here's my attempt at the 'calling' side of the code:

Dim frmTemp As New frmToDoDetail()

frmTemp.lvwTD = lvwToDo
If frmTemp.edit Then...

I do not get any syntax errors, yet the 'passed' listview object is
'nothing'. Am I on the right track?
Thanks.
 
D

David Browne

tmaster said:
Can I pass a listview to another form using a property definition like this?

Public Class frmToDoDetail
Inherits System.Windows.Forms.Form

Private m_lvwTD As ListView

Public Property lvwTD() As ListView
Get
lvwTD = m_lvwTD
End Get
Set(ByVal Value As ListView)
m_lvwTD = lvwTD
End Set
End Property

Your propery definition is messed up.
Should be:

Public Property lvwTD() As ListView
Get
return m_lvwTD
End Get
Set(ByVal Value As ListView)
m_lvwTD = Value
End Set
End Property

Don't use the name of the property as a local variable. It's a bad habit
from VB6, and leads to errors and confusion like you just experienced.

David
 
T

tmaster

Thanks. Your suggestion worked fine.

David Browne said:
Your propery definition is messed up.
Should be:

Public Property lvwTD() As ListView
Get
return m_lvwTD
End Get
Set(ByVal Value As ListView)
m_lvwTD = Value
End Set
End Property

Don't use the name of the property as a local variable. It's a bad habit
from VB6, and leads to errors and confusion like you just experienced.

David
 
H

Herfried K. Wagner [MVP]

* "tmaster said:
Can I pass a listview to another form using a property definition like this?

Public Class frmToDoDetail
Inherits System.Windows.Forms.Form

Private m_lvwTD As ListView

Public Property lvwTD() As ListView
Get
lvwTD = m_lvwTD

Replace the line above with 'Return m_lvwTD'.
 

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