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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:05:06+00:00 2026-05-31T04:05:06+00:00

I have a list box control in my form which contains the paths of

  • 0

I have a list box control in my form which contains the paths of files of particular type from a folder.
On item double click i am adding the page dynamically to the tab control and loading the contents of a file to the object of rich text box. Now i want to edit the contents and save it again . But when i open the saved file the edited contents are not saved it only has earlier contents which were there while loading the file to rich text box.How to update the rich text box object text and save.

 private void lstErrorList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ArrayList errorType = new ArrayList();
            RichTextBox myrich = new RichTextBox();
            string[] list;

            TabPage selectedTab;

            if (lstErrorList.Items.Count > 0)
            {
                string error = lstErrorList.SelectedItem.ToString();
                int result = error.LastIndexOf('\\');
                string filename = error.Substring(result + 1, error.Length - (result + 1));
                list = error.Split(new char[] { '\t' });
                int pagecount;
                TabPage tp = new TabPage();
                pagecount = this.tabControl1.TabPages.Count;
                bool found = false;
                foreach (TabPage tab in tabControl1.TabPages)
                {
                    if (filename.Equals(tab.Name))
                    {
                        tabControl1.SelectedTab = tab;
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    tabControl1.TabPages.Add(filename, filename);
                    tabControl1.SelectedTab = tabControl1.TabPages[tabControl1.TabPages.Count - 1];
                    int i = tabControl1.TabPages.Count;
                    myrich.Height = this.tabControl1.Height - 30;
                    myrich.Width = this.tabControl1.Width - 10;
                    myrich.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom);
                    tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(myrich);
                    string path = list[7];
                    objReader = new System.IO.StreamReader(path);
                    myrich.Text = objReader.ReadToEnd();
                    objReader.Close();
                }

                int val = 0;
                string val1 = list[3];
                string replacement = Regex.Replace(val1, @"\t|\n|\r|[a-zA-Z]", "");
                val = Convert.ToInt32(replacement);
                foreach (Control ct in tabControl1.SelectedTab.Controls)
                {
                    if (ct is RichTextBox)
                    {
                        RichTextBox x = (RichTextBox)ct;

                        x.Select(val, wordToFind.Length);
                        x.SelectionBackColor = Color.Wheat;
                        x.Focus();
                        break;
                    }
                }
            }
        }
 private void mnuValidate_Click(object sender, EventArgs e)
        {                      
            myrich.Refresh();
            myrich.Update();           
            foreach (TabPage page in tabControl1.TabPages)
            {                
                    string Saved_File = "";                
                    saveFD.Title = "Save the file";
                    saveFD.FileName = ChosenFileName;
                    saveFD.Filter = "Text File|*.txt|Html File|*.html|Xhtml File|*.xhtml|XML File|*.xml";
                    Saved_File = saveFD.FileName;
                    foreach (Control ct in tabControl1.SelectedTab.Controls)
                    {
                        if (ct is RichTextBox)
                        {
                            int x = tabControl1.SelectedTab.Controls.IndexOf(ct);
                            MessageBox.Show(x.ToString());
                            ((RichTextBox)page.Controls[x]).SaveFile(Saved_File,RichTextBoxStreamType.RichText);                          

                        }        
}


                    this.tabControl1.TabPages.Remove(page);   


            }           
            lstErrorList.Items.Clear();
            if (filePathlist.Count == 0)
            {
                MessageBox.Show("No input files found,Please upload files and validate again", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (HTML_QC_MultipleFiles.Errors.Checkeditemlist.Count == 0)
                {
                    MessageBox.Show("Please select the error type and validate again", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (singlefile == true)
                    {
                        Validate();
                    }
                    else
                    {
                        bool errorFound = false;
                        string[] words;
                        foreach (string file in filePathlist)
                        {
                            int lineno, index;
                            objReader = new System.IO.StreamReader(file);
                            myrich.Clear();
                            myrich.Height = this.tabControl1.Height - 30;
                            myrich.Width = this.tabControl1.Width - 10;
                            myrich.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom);
                            myrich.Text = objReader.ReadToEnd();
                            ChosenFileName = file;
                            Validate();
                            objReader.Close();
                        }
                    }
                }
            }
        }
  • 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-31T04:05:07+00:00Added an answer on May 31, 2026 at 4:05 am

    I think the problem could be that your code asks for a the filename to save as and then iterates through the set of controls saving each to the same file. If you have two rich text boxes then it could be the efforts of saving the first are overwritten by the second.

    Other things to look out for:

    • Is there an exception during save?
    • Is the file definitely being saved with the same name as the first?
    • Why does you save dialog filter to *.rtf, *.txt and *.html when the SaveFile method only saves RTF?
    • Path manipulations should normally be done via the System.IO.Path class.
    • Consider introducing methods/functions for particular activities so that you don’t end up with such large, wall-of-code methods.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list box control that contains enough items to list them with
I have a form which has a Combo Box Control. I have selected the
I have a form that contains a GridView control which is databound to an
I have the list box control (ASP.NET Control On aspx page, language C# ).
I am trying to make a list box where I have complete control over
i have a list box and i want to add a folder/directory to that
I have a list box and i am trying to get currently checked item
Hello Friends I am using a list box control in aspx page i have
I would like to have a ComboBox control on a form which will be
I have a WPF window which has a ItemsControl which contains list of User

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.