Avatar of GrahamSkan
GrahamSkan
Flag 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.
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
John Tsioumpris

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
John Tsioumpris

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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()'.
John Tsioumpris

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

GrahamSkan

ASKER
Thank you again, John. Unfortunately, that does not make any difference.
Your help has saved me hundreds of hours of internet surfing.
fblack61
John Tsioumpris

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

GrahamSkan

ASKER
Thanks John. I must get some new glasses.
John Tsioumpris

Probably my glasses also carry the same issue...:) ... i had to carry the code to VS to locate it.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
GrahamSkan

ASKER
Thanks for your very prompt help. I can see my conversion project going to take me a lot longer than I first thought
John Tsioumpris

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