Link to home
Start Free TrialLog in
Avatar of GrahamSkan
GrahamSkanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GrahamSkan

ASKER

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()'.
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

Thank you again, John. Unfortunately, that does not make any difference.
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

Thanks John. I must get some new glasses.
Probably my glasses also carry the same issue...:) ... i had to carry the code to VS to locate it.
Thanks for your very prompt help. I can see my conversion project going to take me a lot longer than I first thought
Also about the issue of twips ...you need to convert them to pixels..here is a post to get your started