Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Line Character is not shown in TextBox

I have a form as shown in image below:

enter image description here

Now, When user clicks on Save As Template, I save the text of the textbox in XML File. The Code I use to save this text in XML File is :

public static void SaveTemplate(string Message)
{
    XDocument xmlDocument = XDocument.Load(templatesPath);

    xmlDocument.Element("Templates").Add(
        new XElement("Template", new XAttribute("Id", xmlDocument.Root.Elements("Template").LastOrDefault() != null ? int.Parse(xmlDocument.Root.Elements("Template").LastOrDefault().Attribute("Id").Value) + 1 : 1),
            new XElement("Body", Message)));

    xmlDocument.Save(templatesPath);
}

The text saved in XML file looks like:

enter image description here

After that User may do whatever he wants. When User runs my application again, the textbox is empty. So, he will click on Load Template Button. At that time the text is shown in datagridview:

enter image description here

Now, User clicks on Select Template and the text from DataGridViewCell is copied to textbox again. But the text does not contain new lines. Look at the image below:

enter image description here

Does anybody experienced the same problem in past?

like image 787
Vishal Avatar asked Dec 04 '25 12:12

Vishal


1 Answers

I just had to replace \n with Environment.NewLinelike:

_frmMsgDetails.MessageBody = dgvTemplates.SelectedRows[0].Cells[2].Value.ToString()
                                                .Replace("\n", Environment.NewLine);
like image 66
Vishal Avatar answered Dec 06 '25 03:12

Vishal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!