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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:22:31+00:00 2026-06-09T21:22:31+00:00

I am having difficulties finding a suiteble way as to search a List<> of

  • 0

I am having difficulties finding a suiteble way as to search a List<> of strings i have for matches to a user specified string, I am not even sure i am going about it in the best way but what i got so far is:

   // This is the input string.
        string input = userDefinedStr.ToLower(); //New variable and made into lower cases.           

        for (int i = 0; i < listBox1.Items.Count; i++)
        {
            if (listBox1.Items[i].ToString().IndexOf(input, stringComparison.OrdinalIgnoreCase) >= 0)
            {
                listBox1.SetSelected(i, true);
            }
            else
            {
                MessageBox.Show("Sorry, There was no matches found.", "An oupps happend!");                    
            }

        }

The problem is that there can be more the one string in the List that contains the userdefined string and i guess that the best way is actually to display all the List<string> matches in the listBox1 instead of just marking the first one found.

Or can it be done in another more effective way?!?

I am new to C# and coding in general so i dont feel like i know the best way, i have read so many articles and postings but i cant find the one pointing me in the right direction on 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-09T21:22:33+00:00Added an answer on June 9, 2026 at 9:22 pm

    You’re showing a good start, but with that if statement inside the for, you’re going to get a messagebox popping up for every item that doesn’t match.

    If you wish to use the code you have so far, simply add a bool before the for (initialized to false) and set it to true when you find a match. Once the for is done, test the bool and if it is still false, no match was found and so you should show your messagebox.

    I have suspicions that it can be done in fewer keystrokes in Linq, but it may not be quite as easy to read / understand, depending, and maintainable (/easy to read / understand) code is preferred over clever, as you will have to fix it later.

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

Sidebar

Related Questions

I'm having difficulties seeing why one way works and way doesn't. I have; switch
Im having difficulties creating a query. I have googled a lot but did not
I'm having difficulties parsing a string. This is the structure I have: Title:Avatar,Year:2009,Rated:PG-13,Released:18 Dec
I don't know why I am having difficulties finding an answer for this, but
Although there are some similar questions I’m having difficulties finding an answer on how
I having difficulties setting my footer properly. I have a Bottom navigation bar as
I'm having difficulties finding out how to implement a 'configurable' behavior in a factory
I'm having difficulties adding momentum to my spinning wheel. I have this wheel (something
I am having difficulties understanding AsyncTask, even after reading everything about it on Developer.Android.
I'm having difficulties reading an app.config using the ConfigurationManager. I have a custom section,

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.