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 8213745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:13:25+00:00 2026-06-07T11:13:25+00:00

I am using WinForms/VS2010 c# to create a listview with 12 columns and 8

  • 0

I am using WinForms/VS2010 c# to create a listview with 12 columns and 8 rows. Here is the snippet from the WinForms auto-coded file:

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.listView1 = new System.Windows.Forms.ListView();
       .....
    } 

Then, in the Form1.cs file, I have the following method:

    // in my form1.cs file
    public void listView1_Populate()
    {
        var columnIndex = listView1.Columns[2].Index;
        int counter = 0;

        foreach (ListViewItem item in listView1.Items)
        {
             if (item.SubItems[columnIndex].Text == "2")
             {
                 counter += 100;
                 item.SubItems[columnIndex].Text = counter.ToString(); 
             }
        }
    }

But I get the Object reference not set to an instance of an object exception when the code hits the line: var columnIndex = listView1.Columns[2].Index;

What am I doing wrong (other than trying to learn c# at age 54!)?

  • 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-06-07T11:13:27+00:00Added an answer on June 7, 2026 at 11:13 am

    Its not clear from your question what is null referenced. But if you add the following before this line var columnIndex = listView1.Columns[2].Index; you might get a clearer understanding of whats going wrong.

    if (listView1 == null)
        throw new Exception("listView1 is null");
    if (listView1.Columns == null)
        throw new Exception("Columns is null");
    if (listView1.Columns.Length < 3)
        throw new Exception("Columns length is out of range");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I create a new project of any kind (winforms app/classlib ..) using VS2010
I'm using WinForms TreeView and reaction to AfterLabelEdit event. Here's the snippet of the
Using VS2010 Express, C# and it's WinForms Application. Here I have three text boxes(aTextBox,
I'm using C# for WinForms app in VS2010 and I needed to create a
I am using VS2010, working on a WinForms application that uses the ReportViewer control
I'm using WinForms and C#. The application I am developing draws rows of rectangles
I am using the reportviewer control from VS 2010 to create client side reports
I am using C#, WinForms, In VS2010 Pro and trying to run one line
Using WinForms, C# .Net 2.0 I'm adding rows to a non bound DataGridView. I
I've created a C# WinForms application using VS2010. I'm new to creating user controls

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.