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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:03:46+00:00 2026-05-26T01:03:46+00:00

i have a form with 6 textboxes and a delete button.that i want to

  • 0

i have a form with 6 textboxes and a delete button.that i want to do is to read a text file and save it into a list.after that i want to give a value at the textbox1 and delete the row from the list that this value exists.with this code(i have already done) delete all the values from the text file.what should i change to the code?i use Microsoft Visual C# 2010 Express.

   List<string> StoreItems;

   public Form1()
   {
       InitializeComponent();

       filePath = @"C:\Users\v\Desktop\text.txt";

       StoreItems = new List<string>();
   }



  private void button3_Click(object sender, EventArgs e)
    {


        using (var streamReader = new StreamReader(filePath, Encoding.Default))
        {
            while (!streamReader.EndOfStream)
            {
                StoreItems.Add(streamReader.ReadLine());
            }
        }
        using (var streamWriter = new StreamWriter(filePath, false, Encoding.Default))
        {
            foreach (string line in StoreItems)
            {
                if(line == textBox1.Text)//remove all from the list
                StoreItems.Remove(line);
            }
        }

    }
  • 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-26T01:03:47+00:00Added an answer on May 26, 2026 at 1:03 am

    You can use RemoveAll().

    Removes all the elements that match the conditions defined by the specified predicate.

    There’s no need for explicit iteration over the list. You can just call it like this:

    StoreItems.RemoveAll(item => item == textBox1.Text);
    

    You also forgot to write the list back to the file. I think you want code like this:

    using (var streamReader = new StreamReader(filePath, Encoding.Default))
    {
        while (!streamReader.EndOfStream)
        {
            StoreItems.Add(streamReader.ReadLine());
        }
    }
    
    StoreItems.RemoveAll(item => item == textBox1.Text);
    using (var streamWriter = new StreamWriter(filePath, false, Encoding.Default))
    {
        foreach (string line in StoreItems)
        {
            streamWrite.WriteLine(line);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web form that has multiple ListBoxes, TextBoxes, DropDowns. If I put
I have a UserControl that consists of three TextBoxes. On a form I can
I have a form with 2 text boxes that all do the same thing.
I have a form with several text boxes on it. I only want to
I have a form with 3 textboxes and 1 button. textbox1 has tab index
I have a form with multiple textboxes with the same names. I want to
I have a Form that has a panel with some textBoxes and checkBox that
I have a VB.NET form that contains textboxes for the user to enter his
I have a form with few predefined textboxes, now in addition to that I
I have a form that contains two input textboxes, one called serial and the

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.