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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:44:19+00:00 2026-06-15T02:44:19+00:00

I am adding items to a ListView like this: private int AddThreadToListView(int threadNumber, string

  • 0

I am adding items to a ListView like this:

    private int AddThreadToListView(int threadNumber, string proxy, string query, string page, string links)
    {
        int index = 0;
        listView1.SuspendLayout();

        Invoke(new MethodInvoker(
                       delegate
                       {
                           string[] row1 = { proxy, query, page, links };
                           ListViewItem item = new ListViewItem();

                           listView1.Items.Add(threadNumber.ToString()).SubItems.AddRange(row1);
                           index = listView1.Items.Count - 1;
                       }
                       ));

        if ((listView1.Items.Count % 1000) == 0)
        {
            listView1.ResumeLayout();
            listView1.SuspendLayout();
        }

        listView1.ResumeLayout();
        return index;
    }

I then keep track of the item Index so i can go back and update it from within my threads. (That works great).

The problem however is when i start to remove these items, for some reasons the index changes..

Here are my update and remove methods:

    private void UpdateThreadListView(int threadNumber, string proxy, string query, string page, string links)
    {
        Invoke(new MethodInvoker(
                       delegate
                       {
                           listView1.BeginUpdate();

                           ListViewItem itm = listView1.Items[threadNumber];
                           itm.SubItems[1].Text = proxy;

                           itm.SubItems[2].Text = query;
                           itm.SubItems[3].Text = page;
                           itm.SubItems[4].Text = links;                               

                           listView1.EndUpdate();

                       }
                       ));
    }

    private void RemoveThreadListView(int threadNumber)
    {
        Invoke(new MethodInvoker(
                       delegate
                       {
                           listView1.BeginUpdate();
                           listView1.Items[threadNumber].Remove();
                           listView1.EndUpdate();

                       }
                       ));
    }

I somehow need an index that does not change, a unique one for each listview item created..

How could i accomplish this?

  • 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-15T02:44:20+00:00Added an answer on June 15, 2026 at 2:44 am

    The Index is managed automatically; it represents the location of a given item in the list, so if you remove an item, the position of all subsequent items will change.

    You could use the Tag property of the ListViewItem as a key to search for items using other criteria; e.g.

    private ListViewItem FindItem(object myTag)
    {
        foreach(ListViewItem myItem in listView1.Items)
        {
            if (myItem.Tag.Equals(myTag))
                return myItem;
         }
         return null;
    }
    

    Tag can be set to any object you wish; it’s there essentially for this very purpose (uniquely identifying nodes by means other than the index).

    Note that this will be less efficient than finding elements using the index, since it’s worst-case O(n) (as opposed to O(1) for indexing).

    EDIT:

    The above method is just an example of how to find an item given with a given tag. You can set the tag whenever you want, but in general you’ll probably want to set it when you create the list view item, e.g.

        Invoke(new MethodInvoker(
                       delegate
                       {
                           string[] row1 = { proxy, query, page, links };
                           ListViewItem item = listView1.Items.Add(threadNumber.ToString());
    
                           item.SubItems.AddRange(row1);
                           item.Tag = threadNumber.ToString(); // or whatever you want to search by
                           index = listView1.Items.Count - 1;
                       }
                       ));
    

    Then, assuming you implemented a FindItem() like I gave an example of above, you could do this:

    var item = FindItem("3"); // returns the item tagged with "3"
    

    which in this example would return the item for thread #3.

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

Sidebar

Related Questions

I'd like to move items from one list view to another. adding them to
In my Phonegap android application dynamically adding list items to jqm listview where on
After adding <item>170,000</items> to string.xml . It becomes so slow in building workspace, I
I'm adding items to a jquery mobile listview problematically. I'm currently using jquery templates
Adding contents to listview is a simple proceess like ListViewItem item = new ListViewItem();
I have a ListView which I am constantly adding items in. I am able
I'm using singe page concept jquery mobile. I then create a dynamic listview like
Hi I am using listview which have multiple items adding dynamically.. I want to
I am displaying the Data in to ListView as like below code: private class
I have a listview like this and in FormLoad event I should do some

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.