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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:59:39+00:00 2026-06-17T06:59:39+00:00

I’m using C#. And my question is about a nasty ListBox that just doesn’t

  • 0

I’m using C#. And my question is about a nasty ListBox that just doesn’t want to listen.

Code:

        void client_UserAvailable(object sender, IMAvailEventArgs e)
    {
        this.BeginInvoke(new MethodInvoker(delegate
        {
            if (listBoxContacts.Items != null)
            {
                string available = "";
                if (e.IsAvailable)
                    available = "Online";
                else
                    available = "Offline";

                if (listBoxContacts.Items.Count <= 0 || !listBoxContacts.Items.Contains(e.UserName))
                    listBoxContacts.Items.Add(e.UserName + " " + available);
                else
                {
                    for (int i = 0; i < listBoxContacts.Items.Count; i++)
                    {
                        string _user = (string)listBoxContacts.Items[i];
                        _user.Replace(_user, e.UserName + " " + available);
                    }
                }
            }
        }));
    }

Once I run that event, it will add the user(s) name to the list if the ListBox’s item count is less than or equal to 0 or if the ListBox.Items doesn’t contain the username. If it contains the username or if the count is greater, it will then update the user(s) status in the for loop.

HOWEVER, when trying to replace the value, it just duplicates it. I also tried adding a ‘Remove(_user)’ below ‘_user.Replace(_user, e.UserName + ” ” + available);’, but it just duplicates.

I can fix this issue by adding a ‘ListBox.Items.Clear’ inside of my timer that updates the ListBox at a 5 second interval:

        private void timer_Tick(object sender, EventArgs e)
    {
        if (isOnline)
        {
            if (listBoxContacts.Items != null)
            {
                foreach (string user in friends)
                {
                    listBoxContacts.Items.Clear();
                    client.IsAvailable(user);
                    if (infoWindow != null)
                    {
                        infoWindow.Close();
                        infoWindow = null;
                    }
                }
            }
        }
    }

BUT, the ListBox items blink. I don’t want it to blink, so I’m trying to find alternatives. I searched throughout a lot of related questions, but none were successfully helpful. Help would be greatly appreciated.

  • 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-17T06:59:40+00:00Added an answer on June 17, 2026 at 6:59 am

    Based on comments it looks like the first problem is this clause:

    !listBoxContacts.Items.Contains(e.UserName)
    

    If the existing item is always username + (space) + availability, then that clause will always return false, and therefore always trigger the addition of a new entry.
    You should change that clause to something like:

    (!listBoxContacts.Items.Contains(e.UserName + " Online" ) && !listBoxContacts.Items.Contains(e.UserName + " Offline"))
    

    The next problem is the loop – looks like you end up trying to update the status for everyone in the list, not just the particular user that the event relates to.

    And finally you’re not replacing the existing value in the listbox.

    You probably need to do something like:

    string currentItem = listBoxContacts.Items[i];
    if(currentItem.Contains(e.UserName))
    {
        listBoxContacts.Items[i] = e.UserName + " " + available;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and

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.