tags:

views:

91

answers:

1

Public MaintenanceMenuList As ListView

Function AddItems()

 Dim lstModules As New ListBox()

 MaintenanceMenuList.Items.Add("item_1")
 lstModules.Items.Add(MaintenanceMenuList)

End Function

I am receiving an error like "Object reference not set to an instance of an object". What seems to be the problem here?

A: 

The MaintenanceMenuList Listview object hasn't been created with a/the New keyword

Public MaintenanceMenuList As ListView

Function AddItems()

    Dim lstModules As New ListBox()

    ' if the object is nothing, create it
    If MaintenanceMenuList Is Nothing Then 
        MaintenanceMenuList = New ListView
    End If

    MaintenanceMenuList.Items.Add("item_1")
    lstModules.Items.Add(MaintenanceMenuList)

End Function

Also, your function doesn't return anything or mention what type it will be returning...

EDIT - added response to comment

Change:

lstModules.Items.Add(MaintenanceMenuList)

to:

For Each lvi As ListViewItem In MaintenanceMenuList.Items
    lstModules.Items.Add(lvi.Text)
Next
davidsleeps
The lstModules is displaying this text: "System.Windows.Forms.ListView,Items.Count:4,Items[0]:ListViewItem:{item1}"is it possible to display the text "item_1" only?
sef