accessing a control that's on another form using property

T

tmaster

Within a class, can I create a property that is a listview? Here's what I
tried, but it doesn't seem to work:



'------------ create property to give the second form access to the first
form's listview:

Public Class frmToDoDetail ' (this is the second form)

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 passed listview:

' I've tried all of these references from frmToDoDetail unsuccessfully:

' The error I get is 'Object reference not set to an instance of an object'.

lvwTD.refresh

me.lvwTD.refresh

me.m_lvwTD.refresh



'------------ try to pass the listview. This sub is part of a form (the
first form) that has a listview on it called lvwToDo:

Private Sub lvwToDo_ItemActivate(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lvwToDo.SelectedIndexChanged

Dim frmTemp As New frmToDoDetail()



frmTemp.lvwTD = lvwToDo



'After the above statement executes, the debugger says that
lvwToDo={System.Windows.Form.Listview}, but frmTemp.lvwTD=nothing.
 
C

Craig Vick [MSFT]

Hi tmaster,

It looks like the problem is that the ListView is never created. You may
need something like

Dim m_lvwTD As New ListView

or, you can create the object in your constructor (Sub New)

I hope this helps,
Craig, VB.Net Team
 

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

Similar Threads


Top