Solved

Displaying Multiple Lines on a Winforms DataGrid

Posted on 2003-11-12
4
529 Views
Last Modified: 2010-04-16
Does anyone know how to display data in multiple lines on a datagrid. (Winforms)

Thanks
0
Comment
Question by:heboh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9737876
Actually the DataGrid automatically shows multiline data, separated by \n. What you need to do is only adjust the height of the row so that you can see the whole text. Just for a test, enter programmically a value like "line1\nline2" in a cell in the data grid and resize the row to see both lines.

If you need to edit multiline values, then you have to use a custom table style and column styles and use the property DataGridTextBoxColumn.TextBox.Multiline property to set the text box, which edits the data, to accept multiline.
0
 
LVL 1

Author Comment

by:heboh
ID: 9737987
hi.

what i mean is, when the data length exceeds the width of the column, it automatically displays it to the next line (in display mode not in edit mode).

Thanks.
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 125 total points
ID: 9738012
OK, this is called word wrapping. I think you can implement it like this: intercept the text changed and column resizing events and make manually calculations how long the text is and how wide the column is. Then put the new line characters at the appropriate positions (don't forget to remove old ones...)

Here is an example: you have the size of the column so big, that 4 letters can fit in it. You have the string:
abcd efgh ijk
so you make it:
abcd\nefgh\nijk - 3 lines
Then the user resizes the column so that it now can show 9 characters, so you make the string:
abcd efgh\nijk - 2 lines
Somewhere in the background you will need to keep the original data....
0
 
LVL 1

Author Comment

by:heboh
ID: 9761328
thanks a lot TheAvenger. you have been helping me a lot..
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
placing a checked in the checklistbox based on the value in database table. 3 71
How do I hide MVVM menu items in WPF/XAML? 1 52
array not updating 8 40
C# DateTime Help 6 44
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question