[英]String taken from DataTable to DataGridView: “\n” is not interpreted as new line
I have DataTable which contains some strings with "\\n" signs. 我有DataTable,其中包含一些带有“ \\ n”符号的字符串。 I need to take those strings and put them into DataGridView cells.
我需要将这些字符串放入DataGridView单元中。 "\\n" should be interpreted as new line.
“ \\ n”应解释为换行符。
What I am doing: 我在做什么:
dataGridView1.Rows[1].Cells["actionColumn"].Value = subStepLine["action"].ToString();
where subStepLine["action"]
is cell in DataTable with string inside "firstLine\\n\\nsecondLine" 其中
subStepLine["action"]
是DataTable中具有“ firstLine \\ n \\ nsecondLine”内的字符串的单元格
I want to show it in DataGridView as: 我想在DataGridView中显示为:
"firstLine “第一行
secondLine" 第二行”
but it shows as: "firstLine\\n\\nsecondLine". 但显示为:“ firstLine \\ n \\ nsecondLine”。
On the other hand, when I am doing is like this: 另一方面,当我在做的时候是这样的:
dataGridView1.Rows[1].Cells["actionColumn"].Value = "firstLine\n\nsecondLine"
then it is fine and '\\n\\n' are treated as new lines. 那么就可以了,并且'\\ n \\ n'被视为新行。
I have wrapMode set on true. 我将wrapMode设置为true。
Should I set something in DataTable too? 我也应该在DataTable中设置一些内容吗?
If more code needed I can add it, just dont wanted to do my post unredadable 如果需要更多代码,我可以添加它,只是不想做我的帖子
If I understood correctly, you wish to have a single cell to display a multi line text, if so, try replacing the \\n literals with Environment.NewLine() (that will resolve to \\r\\n). 如果我理解正确,则希望有一个单元格来显示多行文本,如果是这样,请尝试用Environment.NewLine()替换\\ n文字(它将解析为\\ r \\ n)。
This also seems like a duplicate: C#: multiline text in DataGridView control 这似乎也很重复: C#:DataGridView控件中的多行文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.