Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5991143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:20:41+00:00 2026-05-22T23:20:41+00:00

I’ve tried this but it’s giving me ‘System.NullReferenceException’: For Each MyListViewItem As ListViewItem In

  • 0

I’ve tried this but it’s giving me ‘System.NullReferenceException’:

    For Each MyListViewItem As ListViewItem In MyListView.Items
        MsgBox(MyListViewItem.SubItems("MyColumn").Text)
    Next

These lines of codes work (weird!):

    For Each MyListViewItem As ListViewItem In MyListView.Items
        MsgBox(MyListViewItem.SubItems(0).Text)
    Next

But I need to access them by column name.

I found that this code gives me blank subitem name

For Each MyListViewItem As ListViewItem In MyListView.Items
    MsgBox(MyListViewItem.SubItems(0).Name)
Next

Note that I added the columns in design time. While items in run-time:

    While Reader.Read
        Dim SubItems(2) As String
        SubItems(0) = Reader("ItemForMyColumn")
        SubItems(1) = Reader("ItemForSomeOtherColumn")
        MyListView.Items.Add(New ListViewItem(SubItems))
    End While

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:20:42+00:00Added an answer on May 22, 2026 at 11:20 pm

    It is likly throwing the null reference exception when trying to access the Text property on the SubItems(“MyColumn”) part of your sample.

    You could check to see if MyListViewItem.SubItems(“MyColumn”) is not null before trying to read the Text property from it.

    It could also be (based on your edit) that the name you are using to look it up doesn’t match that’s in the SubItems list.

    If you print the name that you are looking for by using the index, what do you see?

    After Edits

    I might be this wrong, but it looks like by using this constructor for the ListViewItem, it’s only going to be getting the Text property set.

    I suggest trying something like this in your init code for the ListViewItem

    (Forgive me, my VB is really really rusty and I don’t have VS open)

    While Reader.Read
       Dim listViewItem As New ListViewItem()
    
       Dim subItem1 As New ListViewSubItem()
       subItem.Text = Reader("ItemForMyColumn")
       subItem1.Name = "MyColumn"
    
       //Do this as many times as you need
    
       listViewItem.SubItems.Add( subItem1 )
    
       MyListView.Items.Add( listViewItem )    
    End While
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.