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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:49:02+00:00 2026-05-26T02:49:02+00:00

RESOLVED Oddly, it appeared that what was happening here, was that the string[] collection

  • 0

RESOLVED

Oddly, it appeared that what was happening here, was that the string[] collection was being iterrated through when it had no elements. Because of that, every single item would be removed from the user list. Added an additional check to ensure that nicks.Count !=0, and it adds and works perfectly. Have to love when code does things you do not expect 😉

—[INITIAL ISSUE]—

So, i’m a bit confused here.

When we connect to our server, we are given a string collection result string[]. We then parse that string collection, and add names to a listview. However, we need to also parse the listview, and remove any items which do not appear in the string collection.

I can’t seem to figure out a way to properly do that. I know it’s easy, but I’ve failed so far at anything I’ve tried, which totally isn’t cool 🙁

Code to filter out the string collection to the listview and not add duplicates:

foreach (var nick in nicks)
        {
            if (string.IsNullOrEmpty(nick)) continue;
            var lvi = new ListViewItem
                          {
                              Text = nick,
                              Group = nick.StartsWith("@") ? listViewEx1.Groups[0] : listViewEx1.Groups[1]
                          };
            if (listViewEx1.Items.Count != 0)
            {
                var foundItem = listViewEx1.FindItemWithText(nick, true, 0, false);
                if (foundItem != null) continue;
            }
            lvi.ImageIndex = 0;
            listViewEx1.Items.Add(lvi);
        }

So, how can I conversely compare the items in the listview, with the items in the string collection, and remove those that do not exist?

Debug Information

Element in 'nicks':   Bot
Element in 'nicks':   Test
Element in 'nicks':   @Mike
Element in 'nicks':   @Jack
Element in 'nicks':   Joe
Element in 'nicks':   Nancy
Element in 'nicks':   Roger
Element in 'nicks':   
Does not contain:  @Mike
Does not contain:  @Jack
Does not contain:  Bot
Does not contain:  Joe
Does not contain:  Test
Does not contain:  Nancy
Does not contain:  Roger

So oddly, even though the nicks[] collection contains the item, and the item.Text contains the nick, the .Contains() call is not matching it.

  • 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-26T02:49:02+00:00Added an answer on May 26, 2026 at 2:49 am

    If these are just simple strings then something like this should work:

    List<ListViewItem> itemsToRemove = new List<ListViewItem>();
    foreach(ListViewItem item in listViewEx1.Items)
    {
       if(!nicks.Contains(item.Text))
          itemsToRemove.Add(item.Text);
    }
    
    foreach(ListViewItem item in itemsToRemove)
       listViewEx1.Items.Remove(item);
    

    The reason for the separate remove loop is that you don’t want to modify the Items collection during an iteration, otherwise you get an exception.

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

Sidebar

Related Questions

Here is a little problem that cannot be resolved by me such a Linux
Had another thread regarding this but it wasn't resolved probably because I wasn't very
RESOLVED EDIT: Because it is not clear through the discussion nothing was really wrong
Resolved: I had $_SERVER['REQUEST_METHOD'] != 'post' as lowercase. That has to be capital apparently...
With your help I have successfully resolved a question that I have asked here
RESOLVED From the developer: the problem was that a previous version of the code
I resolved this issue myself. It turns out that the activation framework requires some
I recently resolved an issue my VB6 application had when saving large binary objects
This is a perennial question for me that I've never really resolved so I'd
__thread Foo foo; How is foo actually resolved? Does the compiler silently replace every

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.