Carriage Return in DataColumn.Expression

G

Guest

Hi all,
When concatenating strings in a datacolumn.expression for a computed
datacolumn, is there a special character I can insert to specify that I want
a carriage return (Environment.NewLine) between two of the strings?

Thank you.
 
G

Guest

Hi Manish,
You know, I had seen that in the MSDN documentation and tried it. All it
does is insert the literal \n into the concatenated output string. It does
not cause a new line behavior.
 
W

WenYuan Wang [MSFT]

Dear John

As far as I know the characters '\r\n' really could display as new line.
You may try:
dataTable.Columns.Add("WrapColumn", typeof(string), "[c1]+\'\r\n\'+[c2]");

Make sure you type "[c1]+\'\r\n\'+[c2]" in the express property of Column.
@"[c1]+'\r\n\'+[c2]" is not correct, due to @-quoting is that escape
sequences are not processed.

In Addition, by default, text in a DataGridViewTextBoxCell does not wrap.
new line characters in the text do not apply and so they are displayed as a
"non-printable" character.
If you want to display such characters in DataGridView, you may controll
WrapMode property on the cell style.
this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

Hope this helps. Please let me know if you meet any futher issue or have
anything unclear. I'm glad to assist you. Have a great day. Thanks.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks WenYuan,
Unfortunately, the expression you describe gives me a syntax error -
unrecognized token '\'
I am actually trying to use this to concatenate several fields from drop
down custom controls into a richtextbox.
 
W

WenYuan Wang [MSFT]

Dear John,
Thanks for your reply.

It seems like your scenario a little complicated. You want to concatenate
the value from several drop down custom controls and display it into a rich
textbox. Is this true? Please feel free to correct me if I misunderstand
anything here. Thanks.

I have tested it on my side and it works as except. In order to narrow
down the issue, please provide some additional information about your
Application.
1) Would you please past some code snippet in newsgroup? Thus we can
understand why you concatenated the string.
2) Would you please past the exact expression in your column when you
receive the error message "syntax error - unrecognized token '\'". This is
helpful very much.
3) At last but not least, I just want to make sure you are using VS 2005.
If you are VS 2003 or anything else, please let me know.

I'm waiting for your reply. Have a great weekend. Thanks.
Sincerely,
Wen Yuan
Microsoft Online Community Support
====================
This posting is provided "AS IS" with no warranties, and confers no rights
 
W

WenYuan Wang [MSFT]

Hello John,

How are you? This is Wen Yuan again. Have you resolved the issue so far?
Under my test, "[c1]+\'\r\n\'+[c2]" works fine on my side. If the issue
still persists, would you please provide me some additional information for
me? I understand it is difficult to collect so much information in one
time. However, after collecting such information, we move more quickly
toward the solution.

Have a nice day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top