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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:12:23+00:00 2026-06-11T14:12:23+00:00

I have two listboxes with several data, ListBox1 have this format: C:\Users\Charlie\Desktop\Trials\Trial0004COP.txt and in

  • 0

I have two listboxes with several data, ListBox1 have this format:

C:\Users\Charlie\Desktop\Trials\Trial0004COP.txt

and in my ListBox2:

Trial0004COP

How can I check if Trial0004COP exists in my listbox1? I used Contain() but it doesn’t work.

  • 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-11T14:12:24+00:00Added an answer on June 11, 2026 at 2:12 pm

    What about:

    bool found = listBox1.Items.Cast<string>()
                               .Where(x => x.Contains("Trial0004COP"))
                               .Any();
    

    Or to make it more accurate use String.EndsWith() method but you also have to add ".txt" if you want to make it works:

    bool found = listBox1.Items.Cast<string>()
                               .Where(x => x.EndsWith("Trial0004COP.txt"))
                               .Any();
    

    Edit :

    Hi Fuex, I’m using OpenFileDialog to select a file, then this file is
    added to my listbox1 with all the Directory name. In my listbox2 I
    read another file that contains several Trials000″”” and add them to
    it, I want to know if the file that I selected from the open dialog
    exist in my listboz2

    Yes can do it in this way:

    bool found = false;
    if(openFileDialog.ShowDialog() == DialogResult.OK){
       found = listBox.Items.Cast<string>()
                            .Where(x => x.EndsWith(openFileDialog.FileName))
                            .Any();
    
       if(!found)
          MessageBox.Show(openFileDialog.FileName + " doesn't exist in listBox1"); //show a message
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In form1 I have two listboxs: listbox1, listbox2; loadbutton and savebutton This code will
I have two listboxes. The listbox1 contains a list of the DB names. Listbox2,
I have a two stacked listboxes with data(first ListBox contains <10 elements, second may
I have two ListBoxes. First ListBox items are list of Products. and second ListBox
I have two ListBoxes, lstAvailableColors and lstSelectedColors. Between each listbox are two buttons, Add
i have two ListBoxes (in a Silverlight 3 Application), each wrapped with a ListBoxDragDropTarget.
I have a form with a dropdownbox two listboxes and two buttons on it.
I have two tables, employees and project , in listbox2 , I show all
I have a databound listbox which is actually displaying two columns of data. It
I have two ListBoxes bound to DataTables. When I try to move information from

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.