如果填充当前行宽,WinForm会自动换行 [英] WinForm wrap text if current row width is filled
问题描述
我的WinForm中有DataGridView。我将 AutoSizeColumnsMode
设置为 Fill
,因为如果用户调整窗口大小,则不需要空格。
I have DataGridView inside my WinForm. I set AutoSizeColumnsMode
to Fill
, because I need no white space if user resizes the window.
我想要实现的目标。例如,用户在特定单元格中键入一些文本。当文本宽度变为单元格宽度时,文本必须换行。
可能是这样的:
What I want to achieve. For example, user types some text in the certain cell. When text width becomes as cell width, text must go one the new line.
How it might be:
|Cell Header|
-------------
|text-text |
和
|Cell Header|
-------------
|text-text |
|more text |
|on the new |
|line |
我的列可以按用户调整大小。因此:
My columns are resizable by user. So this:
|Cell Header|
-------------
|text-text |
|more text |
|on the new |
|line |
可能会这样做:
|Cell Header |
---------------------
|text-text more text|
|on the new line |
我从其他方法得到的答案:
What I have tried from other SO answers:
- 将
AutoResizeRowsMode
设置为AllCells
-没有帮助 - 将
DefaultCellStyle.WrapMode
设置为True
-不会帮助
- set
AutoResizeRowsMode
toAllCells
- didn't help - set
DefaultCellStyle.WrapMode
toTrue
- ddin't help
我实际上如何实现?
编辑:列设置:
编辑#2:
推荐答案
设置 RowsDefaultCellStyle.Wrapm ode = true
而不是 DefaultCellStyle.WrapMode = true
我对两个网格都使用了默认设置。这是我的设置:
I used default settings for both of the grid. This is my settings :
这是代码
这篇关于如果填充当前行宽,WinForm会自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!