We help IT Professionals succeed at work.

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

188 Views
Last Modified: 2019-02-27
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

IT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
GrahamSkanRetired
CERTIFIED EXPERT
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 TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

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

GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Author

Commented:
Thank you again, John. Unfortunately, that does not make any difference.
John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

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
CERTIFIED EXPERT
Top Expert 2012

Author

Commented:
Thanks John. I must get some new glasses.
John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Probably my glasses also carry the same issue...:) ... i had to carry the code to VS to locate it.
GrahamSkanRetired
CERTIFIED EXPERT
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 TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions