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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:50:36+00:00 2026-06-04T08:50:36+00:00

I have a listView that is being updated from multiple threads, with the threads

  • 0

I have a listView that is being updated from multiple threads, with the threads status and id being displayed. When a thread has ended the item is removed.

My problem is that the way i use to update my listView is by using the listViews ID (to locate the subitems i wish to update). Now, as listView items start getting removed i run into problems because that ID for a specific thread has changed..

Here is the code i currently use to update and remove:

    private void AddToListViewThread(string user, string status, int threadNumber)
    {
        Invoke(new MethodInvoker(
                       delegate
                       {
                           listView2.BeginUpdate();
                           this.listView2.Items[threadNumber].SubItems[1].Text = user;
                           this.listView2.Items[threadNumber].SubItems[2].Text = status;
                           listView2.EndUpdate();
                       }
                       ));
    }

    private void RemoveFromListViewThread(int threadNumber)
    {
        Invoke(new 
            MethodInvoker(
                       delegate
                       {
                           listView2.BeginUpdate();
                           this.listView2.Items.RemoveAt(threadNumber);
                           listView2.EndUpdate();
                       }
                       ));
    }

I now understand that i cannot use the threadNumber as the item index (as items get removed) is there any other way i could achieve this? maybe by targeting the “user” subitem? and then getting subitems from that?

  • 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-04T08:50:38+00:00Added an answer on June 4, 2026 at 8:50 am

    Use the tag property of the ListViewItem to store a different index (similar to the SQL autoincrement ).

    The Tag property is a field used to store metadata about the item.

    A simple binary search would let you find the item to remove in Log(n) time.

    Your code would looks like this:

    private void AddToListViewThread(string user, string status, int threadNumber)
    {
        Invoke(new MethodInvoker(
                       delegate
                       {
                           listView2.BeginUpdate();
                           int i = SearchItem(listView2, threadNumber);
                           if ( i > -1)
                           {
                           this.listView2.Items[i].SubItems[1].Text = user;
                           this.listView2.Items[i].SubItems[2].Text = status;
                           }
                           listView2.EndUpdate();
                       }
                       ));
    }
    
    private void RemoveFromListViewThread(int threadNumber)
    {
        Invoke(new MethodInvoker(
                       delegate
                       {
                           listView2.BeginUpdate();
                           int i = SearchItem(listView2, threadNumber);
                           if ( i > -1)
                           {
                               this.listView2.Items.RemoveAt(i);
                           }
                           listView2.EndUpdate();
                       }
                       ));
    }
    
    private int SearchItem(ListView list, int id)
    { 
             for (int i  = 0; i < list.Items.Count; i++) // I used sequential search but you can implement binary instead
             {
                if (((int)list.Items[i].Tag) == id) return i;
             }
             return -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have a ListView that I am populating with items from an ObservableCollection .
A have a ListView that is rendered with multiple items. Now I want to
I have a ListView that gets updated frequently, at irregular intervals. I want it
I have a ListView in which each item has a SeekBar. When I update
I have a ListView that has some minor visual preferences that are set in
So I have one activity with a listview in it that is dynamically updated
I am using a listView that is being populated from a database. I know
How can a have a ListView that has different amount of rows? Instead of
I have a ListView that is being populated with a custom adapter. I have

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.