Solved

Displaying Multiple Lines on a Winforms DataGrid

Posted on 2003-11-12
4
522 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

822 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