Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to get a DataGridViewTextBoxCell to act like multiline textbox without wordwrap?
 

How to get a DataGridViewTextBoxCell to act like multiline textbox without wordwrap?

If the DefaultCellStyle.WrapMode of aDataGridViewTextBoxColumn is set to true, it will wrap bothlong lines AND lines separated by a newline. What I need is the behavior of a TextBox, when MultiLine is true but WordWrap is false. The textbox will then show the multiple lines, but NOT wrap text within a line. Characters that don't fit within the horizontal area of the textbox are clipped.

I understand that handling cell painting manually could accomplish the horizontal clipping, but I also need to resize the cell and row vertically to be sure that the start ofeach linewithin a cell isvisible. Is this possible and how?
kaborka  Wednesday, September 30, 2009 12:14 AM

Hi kaborka,

Based on my understanding, we can call the TextRenderer.MeasureText method to calculate the width and then resize the width and height of the cell. Please take a look at this thread which shows how to call that method:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/87a668d5-5fa8-44f0-a831-94f4e82db8ca

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer bykaborka Friday, October 02, 2009 4:34 PM
  •  
Aland Li  Friday, October 02, 2009 6:57 AM

Hi kaborka,

Based on my understanding, we can call the TextRenderer.MeasureText method to calculate the width and then resize the width and height of the cell. Please take a look at this thread which shows how to call that method:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/87a668d5-5fa8-44f0-a831-94f4e82db8ca

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer bykaborka Friday, October 02, 2009 4:34 PM
  •  
Aland Li  Friday, October 02, 2009 6:57 AM
Thanks, Aland, that sounds like exactly what I need.  In the past I've used an Autosize label to measure text before resizing a textbox to display it, but this sounds like a better solution.  I will mark your post as the answer for now and reopen this later if I have a problem.
kaborka  Friday, October 02, 2009 4:34 PM
Hi kaborka,

You are welcome. Please feel free to let me know if you need more information or a code snippet.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, October 05, 2009 2:40 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridViewCheckBoxColumn check/uncheck Question - 2.0 framework
• dir/file listing in a ComboBox/ListView
• Combobox Autocomplete faulty??
• Complicated DataGridView with Combobox problem
• Shortcut Keys to Trigger BindingNavigator Button Key Press Event
• cannot get the correct value after change the selected row
• Why are getters called so many times on data bound object properties ?
• Yes! Another DataGridViewComboBoxColumn Question!
• DataGridView with frequently updated DataSource
• Array.ForEach for other types