Answered by:
Column wrapping and acceptReturns functions

Question
-
Hi everyone,
Well I know that with a normal textbox textwrapping and AcceptReturns is used to keep the textbox one width and to display all data on new lines when that line widt is exceeded...
Can anybody please tell me how to do the same with a column in a datagrid... I've got a datagrid and the messages can be any rage of size... Can somebody please help?
Thanks very much in advance!!!
Rising Storm TechnologiesTuesday, March 8, 2011 1:41 PM
Answers
-
Hi linkit,
Instead DataGridText column, you have to use DataGridTemplateColumn with TextBox in it.
Try the following code.
<DataGridTemplateColumn Header="Value" Width="*" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Value}" AcceptsReturn="True" TextWrapping="Wrap" Height="150" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"></TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>Reference:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a4ced4a0-9949-455b-a405-92e500303848
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.- Marked as answer by linkit Monday, March 14, 2011 8:21 AM
Tuesday, March 8, 2011 2:13 PM
All replies
-
Hi linkit,
Instead DataGridText column, you have to use DataGridTemplateColumn with TextBox in it.
Try the following code.
<DataGridTemplateColumn Header="Value" Width="*" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Value}" AcceptsReturn="True" TextWrapping="Wrap" Height="150" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"></TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>Reference:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a4ced4a0-9949-455b-a405-92e500303848
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.- Marked as answer by linkit Monday, March 14, 2011 8:21 AM
Tuesday, March 8, 2011 2:13 PM -
Hi ksvimal,
Thanks for your reply!!! I'm so sorry, I didn't explain it properly... this datagrid uses label templates to make sure it is not editable... so instead of a textbox I used a label template... Do you know of a way that I can still achieve the same goal?
Thanks so very much!!!
Kind Regards
Rising Storm TechnologiesTuesday, March 8, 2011 2:18 PM -
Hi linkit,
If it not editable then you can use TextBlock instead of Label. Here you will get the TextWrapping property, set this property to "Wrap" and try.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.Tuesday, March 8, 2011 2:31 PM -
Hi linkit,
Is your problem solved? If not then please feel free to inform us. So we can help you.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.Monday, March 14, 2011 7:42 AM -
Hi ksvimal,
Thanks, but I'm still trying to get it to work... The TextBlock isn't wrapping the text... I'm still searching to find a way to do this....
Thanks
Rising Storm TechnologiesMonday, March 14, 2011 7:44 AM -
Hi linkit,
--> The TextBlock isn't wrapping the text
Could you share some codes?
Best regards,
Stay hungry, stay foolishMonday, March 14, 2011 7:48 AM -
Hi ksvimal,
Thanks I've found the solution... Thanks very much... I forgot about a propperty that should've been in... Thanks though and my apologies for the bother...
Kind Regards
Rising Storm TechnologiesMonday, March 14, 2011 8:02 AM -
Hi linkit,
Could you close this thread as "Answered"?
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, March 14, 2011 8:11 AM