Solved

Displaying Multiple Lines on a Winforms DataGrid

Posted on 2003-11-12
4
517 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks a lot TheAvenger. you have been helping me a lot..
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now