Reference to a non-shared member requires an object reference.

GrahamSkan
GrahamSkan used Ask the Experts™
on
A windows update has put paid to my VB6 installation, so I am blundering about trying convert a project to VB.NET
This code
        Dim ch As ColumnHeader

        With ListView1
            ch = .ColumnHeaderCollection.Add("Letter", 1500)
            ch = .ColumnHeaderCollection.Add("Vol Name", 1500)
            ch = .ColumnHeaderCollection.Add("Type", 1500)

Open in new window

gives this error on the last three lines.

Error      BC30469      Reference to a non-shared member requires an object reference.      

I have no idea what is supposed to be shared.

Googling shows some answers, but they all seem to refer to user-written classes, not standard controls.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software & Systems Engineer
Commented:
Take a look at this sample
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim lst1 As New ColumnHeader
        Dim lst2 As New ColumnHeader
        Dim lst3 As New ColumnHeader
        Dim ltm1 As New ListViewItem(New String() {"A", "A1"}, -1)
        Dim ltm2 As New ListViewItem(New String() {"", "", "B"})
        Dim ltm3 As New ListViewItem({"", "C", ""})

        lst1.Text = "header1"
        lst2.Text = "header2"
        lst3.Text = "header3"

        Me.ListView1.Columns.AddRange(New ColumnHeader() {lst1, lst2, lst3})
        Me.ListView1.Items.AddRange(New ListViewItem() {ltm1, ltm2, ltm3})
    End Sub

Open in new window

GrahamSkanRetired
Top Expert 2012

Author

Commented:
Hi John
Thanks for that . I am trying to specialise your code to fit my situation
      '...      
        Dim ch1 As New ColumnHeader
        Dim ch2 As New ColumnHeader
        Dim ch3 As New ColumnHeader
        With ListView1
            ch1.Text = "Letter"
            ch1.Width = 1500
            ch2.Text = "Vol Name"
            ch2.Width = 1500
            ch3.Text = "Type"
            ch3.Width = 1500

            .Columns.AddRange(New ColumnHeader(), ch1, ch2, ch3)
 '...

Open in new window

Unfortunately it finds an error on  'New ColumnHeader()':

Error      BC30311      Value of type 'ColumnHeader' cannot be converted to 'ColumnHeader()'.
John TsioumprisSoftware & Systems Engineer

Commented:
if you mean here:
.Columns.AddRange(New ColumnHeader(), ch1, ch2, ch3)

Open in new window

then it should be
.Columns.AddRange(New ColumnHeader(), {ch1, ch2, ch3})

Open in new window

Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

GrahamSkanRetired
Top Expert 2012

Author

Commented:
Thank you again, John. Unfortunately, that does not make any difference.
John TsioumprisSoftware & Systems Engineer

Commented:
The comma was the issue ...missed it
.Columns.AddRange(New ColumnHeader() {ch1, ch2, ch3})

Open in new window


In order to be clear the offending code is :
Columns.AddRange(New ColumnHeader(), {ch1, ch2, ch3})

Also .NET handles width differently ...so for start just divide the width by a factor of 10
 Dim ch1 As New ColumnHeader
        Dim ch2 As New ColumnHeader
        Dim ch3 As New ColumnHeader
        With ListView1
            ch1.Text = "Letter"
            ch1.Width = 150
            ch2.Text = "Vol Name"
            ch2.Width = 150
            ch3.Text = "Type"
            ch3.Width = 150

            '.Columns.AddRange(New ColumnHeader(), {ch1, ch2, ch3})
            .Columns.AddRange(New ColumnHeader() {ch1, ch2, ch3})
        End With

Open in new window

GrahamSkanRetired
Top Expert 2012

Author

Commented:
Thanks John. I must get some new glasses.
John TsioumprisSoftware & Systems Engineer

Commented:
Probably my glasses also carry the same issue...:) ... i had to carry the code to VS to locate it.
GrahamSkanRetired
Top Expert 2012

Author

Commented:
Thanks for your very prompt help. I can see my conversion project going to take me a lot longer than I first thought
John TsioumprisSoftware & Systems Engineer

Commented:
Also about the issue of twips ...you need to convert them to pixels..here is a post to get your started

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial