c# - 如果当前行宽已满,WinForm 换行

标签 c# .net winforms datagridview

我的 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 答案中尝试过的内容:

  • AutoResizeRowsMo​​de 设置为 AllCells - 没有帮助
  • DefaultCellStyle.WrapMode 设置为 True - 没用

我怎样才能真正做到这一点?

编辑:列设置:

enter image description here

编辑#2:

enter image description here enter image description here

最佳答案

设置 RowsDefaultCellStyle.Wrapmode = true 而不是 DefaultCellStyle.WrapMode = true

enter image description here

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

enter image description here

这是代码

enter image description here

关于c# - 如果当前行宽已满,WinForm 换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52126413/

相关文章:

从另一个类调用方法后,C# 设置 Form Parent

c# - 如何在 PictureBox 中平移图像

c# - 如何从 Web.config 读取 system.net/mailSettings/smtp

c# - 当 StackPanel 宽度为全宽时,WP8 ListBox DataTemplate 抛出异常

c# - 如何在 C# 中禁用无参数构造函数

.net - 将 AssemblyInfo.cs 中的程序集版本放入 Web.config

c# - 从ElasticSearch查询获取完整值(value)

c# - 从数据库到文本框的数据

c# - List.Add() 在 C# 中不起作用 - getter 和 setter 问题?

c# - 如何实现像 SQL Server Results 面板那样的多个网格