Help!

  • Thread starter Thread starter Ash
  • Start date Start date
A

Ash

Ok, in VB6, if, for instance, I was in "frmAdd", I could use the code:

Dim X as ListItem
X = frmMain.lvwMain.ListItems.Add("blah")

VB .NET doesn't seem to allow me to access controls on the form (that I can see).

Anybody know how I can do this?

Thanks in advance,
Ash
 
* (e-mail address removed) (Ash) scripsit:
Ok, in VB6, if, for instance, I was in "frmAdd", I could use the code:

Dim X as ListItem
X = frmMain.lvwMain.ListItems.Add("blah")

VB .NET doesn't seem to allow me to access controls on the form (that I can see).

Let 'MainForm' be the class name of your app's main form. Add the code
below to your project, then go to the project settings and change the
startup object to 'Sub Main':

\\\
Public Module Program
Private m_MainForm As MainForm

Public ReadOnly Property MainForm() As MainForm
Get
Return m_MainForm
End Get
End Property

Public Sub Main()
m_MainForm = New MainForm()
Application.Run(m_MainForm)
End Sub
End Module
///

You can access the main form from everywhere in the app by typing
'Program.MainForm'.

- or -

\\\
Public Class Program
Private Shared m_MainForm As MainForm

Public Shared ReadOnly Property MainForm() As MainForm
Get
Return m_MainForm
End Get
End Property

Public Shared Sub Main()
m_MainForm = New MainForm()
Application.Run(m_MainForm)
End Sub
End Class
///

There are still some alternatives, for example, you can implement the
singleton design pattern for your forms in order to access them by their
class name.
 
What you are trying to do with your code is not legal. You have declared a
variable X of type ListItem. ListItem is a class so X becomes an Object
variable.

You have not instantiated X so therefore you cannot use it yet.

example X = New ListItem

Next, you attempt to do an assignment to X by calling the Add method of the
ListView control's Items collection. This is not correct.

What exactly is it, that you are tyring to accomplish?

If you are trying to add a ListItem to the ListView control then you must do
this;


Dim X As New ListViewItem

X.Text = "blah"

lvwMain.Items.Add(X)


If you want to assign the ListView item to X, that is another story
altogether as you would have to know which item in the ListView you want to
extract.
 
(e-mail address removed) (Ash) wrote in
VB .NET doesn't seem to allow me to access controls on the form (that
I can see).

Did you declare the controls at the class level?
 
Ok, in VB6, if, for instance, I was in "frmAdd", I could use the code:

Dim X as ListItem
X = frmMain.lvwMain.ListItems.Add("blah")

VB .NET doesn't seem to allow me to access controls on the form (that I
can see).

Make sure the Modifiers property for the control is not set to Private or
Protected. This answer assumes that the only issue here is access to the
control on the other form and not some other syntactical error as others
have suggested it may be.
 
Ahs,

The VB6 form control array disapeared.

However the form has that still now almost the same however the name is a
control collection and it is now for every control.

So when you have a panel you can add that panel as
dim mypanel as new panel
me.controls.add(mypanel)

However you can add to that panel again a panel
dim mypanel1 as new panel
myPanel.controls.add(mypanel1)

They both are invisible however when you color them first you will see them.

I hope this helps?

Cor
 

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

Back
Top