When adding data to ListBox, determine whether the added data already exists in ListBox

Source: Internet
Author: User

Use openfiledialog to select a file and put the selected file into ListBox. If you want to determine that the data to be added already exists in ListBox, do not add it.

I thought it was loop traversal, but it was very troublesome. I found a method on the Internet,

Directly paste the code

String STR = "";
If (openfiledialog1.showdialog () = dialogresult. OK)
{
For (INT I = 0; I <openfiledialog1.filenames. length; I ++)
{
STR = openfiledialog1.filenames. getvalue (I). tostring ();
// Determine whether the object exists in The ListBox set. If the object does not exist, add the object.
If (! Listbox1.items. Contains (STR ))
{
Listbox1.items. Add (STR );
}


}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.