Solved

Displaying Multiple Lines on a Winforms DataGrid

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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