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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:54:29+00:00 2026-05-20T05:54:29+00:00

I have a listview in WPF and C# that uses an ObservableCollection to populate

  • 0

I have a listview in WPF and C# that uses an ObservableCollection to populate the data. When a certain event is fired, I call a function to insert a new row into the collection. I then need to access the controls in that row.

The problem i am having is that after i insert the row, and I try to loop through the listview rows, this row is displaying as null in my loop.

       if (addNewNote)
        {

            _resultsCollection.Insert(0, new ResultsData
            {
                Notes = "Data to Insert",
                // ... rest of fields

            });

        } // end if (addNewNote)

        for (int currRowIndex = 0; currRowIndex < this.ResultsList.Items.Count; currRowIndex++)
        {
            System.Windows.Controls.ListViewItem currRow =
                (System.Windows.Controls.ListViewItem)this.ResultsList.ItemContainerGenerator.ContainerFromIndex(currRowIndex);

            if (currRow != null)
            {
                System.Windows.Controls.TextBox tb = FindByName("EditNotesTextBox", currRow) as System.Windows.Controls.TextBox;

        // do stuff with controls ...
            }
        } 

Here currRow is always null, when the currRowIndex is zero.

This should not be the case, because i have just added it. Is it because I am trying to access it in the same function where I insert it, and the listview has not yet been updated? I am able to access every other row in the listview. Is there a better solution? Thanks!

  • 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-20T05:54:30+00:00Added an answer on May 20, 2026 at 5:54 am

    In order to newly added item to be accessible first the container for that item (UI) needs to be generated by ItemContainerGenrator. The generation is done on the same (UI) thread, so you cannot access containers right after you have added an item.

    You can subscribe to ResultsList.ItemContainerGenerator.StatusChanged event and in the event handler check if the status is GeneratorStatus.ContainersGenerated then you can obtain the container.

    ResultsList.ItemContainerGenerator.StatusChanged += OnGeneratorStatusChanged;
    
    ...
    
    private void OnGeneratorStatusChanged(object sender, EventArgs e)
    {
        if (MyListBox.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
        {
            // Access containers for newly added items
        }        
    }
    

    Please refer to this article by Dr.WPF that describes how it works in detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView in WPF that is databound to a basic table that
I have a WPF ListView that is bound to a BindingList<T>. The binding works
I have a WPF ListView which repeats the data vertically. I cannot figure out
I have used a list view that uses a grid view in WPF. I
I have a WPf ListView that i am replacing the View with GridView to
I have a WPF ListView that I am trying to filter within a BackgroundWorker.
I have a WPF ListView that contains CheckBox column and other columns of the
I have a ListView that uses a custom adapter. The custom adapter's getView uses
I have a ListView on a page that displays a list of widgets. When
I have a listview with a DataTemplate that has a ComboBox. I want the

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.