Solved

Displaying Multiple Lines on a Winforms DataGrid

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 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