0

Hi, ive generated files from a text file to a checklist box. now i want to delete some of it, example i have anna on the first check box and when i check it and click on the delete command the name anna will be removed from the checklist box together with its name on the text file. help pls. thanks.

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by dc_24l
0

Hi,

This is how to delete it from the CheckBoxList :

private void buttonDeleteItem_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < this.checkedListBox1.CheckedItems.Count; i++ )
     { 
       this.checkedListBox1.Items.Remove(this.checkedListBox1.CheckedItems[i]);

      string modified = theStringFromWhereYouLoadTheTextBox.Replace(this.checkedListBox.CheckedItems[i].ToString(), string.Empty );//And then Create a new file with same name that the original from modified
               
       }
  }

the replace part depends on how your text file is formatted.

Regards,
Camilo

0

hi i have this code in generating the data from the text to the checklist box

public void frmView_Load(object sender, EventArgs e)
        {
            string line;

            using (StreamReader reader = File.OpenText(@"C:\sample.txt"))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    checkbox.Items.Add(line);
                }
            }

but i cant find the line variable in my class string modified here in the example

private void buttonDeleteItem_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < this.checkedListBox1.CheckedItems.Count; i++ )
     { 
       this.checkedListBox1.Items.Remove(this.checkedListBox1.CheckedItems[i]);

      string modified = theStringFromWhereYouLoadTheTextBox.Replace(this.checkedListBox.CheckedItems[i].ToString(), string.Empty );//And then Create a new file with same name that the original from modified
               
       }
  }

still i cant save the items in the check list box to the txt file thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.