如果填充当前行宽,则WinForm换行文本

问题描述 投票:1回答:2

我在WinForm中有DataGridView。我将AutoSizeColumnsMode设置为Fill,因为如果用户调整窗口大小,我不需要空格。

我想要实现的目标。例如,用户在特定单元格中键入一些文本。当文本宽度变为单元格宽度时,文本必须是新行的一个。 怎么样:

|Cell Header|
-------------
|text-text  |

|Cell Header|
-------------
|text-text  |
|more text  |
|on the new |
|line       |

我的列可由用户调整大小。所以这:

|Cell Header|
-------------
|text-text  |
|more text  |
|on the new |
|line       |

可能会这样:

|Cell Header        |
---------------------
|text-text more text|
|on the new line    |

我从其他SO答案中尝试过:

  • AutoResizeRowsMode设为AllCells - 没有帮助
  • 将qazxsw poi设为qazxsw poi - 没有帮助

我怎么能实现这个呢?

编辑:列设置:

DefaultCellStyle.WrapMode

编辑#2:

True enter image description here

c# .net winforms datagridview
2个回答
2
投票

设置enter image description here而不是enter image description here

RowsDefaultCellStyle.Wrapmode = true

我使用了两个网格的默认设置。这是我的设置:

DefaultCellStyle.WrapMode = true

这是代码

enter image description here


1
投票

除了为列设置包装模式和自动大小模式之外,还需要为行设置大小模式。

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.