在 datagridview中,编辑某个单元格,当输入内容超过单元格长度时,单元格长度并没有增加,怎样让其根据内容自动变换呢?

ahking 2012-02-11 09:53:14
在 datagridview中,编辑某个单元格,当输入内容超过单元格长度时,单元格长度并没有增加,
怎样让其根据内容自动变换呢?
...全文
199 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
木水云 2012-02-11
  • 打赏
  • 举报
回复
楼上威武,受教了!
WAN 2012-02-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ahking 的回复:]
引用 1 楼 foreachif 的回复:

编辑列... -> 将列的 AutoSizeMode属性 设置为 AllCells
或:
C# code
dataGridView1.Columns["column1"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;


这个我设置了,可以不起作用,不知是哪给限制住了
[/Quote]
试一试重置DataGridView的AutoSizeColumnMode属性
另外这个属性要在编辑提交之后才会调整列宽
  • 打赏
  • 举报
回复
都已经说了, 就是改个属性
ahking 2012-02-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 foreachif 的回复:]

编辑列... -> 将列的 AutoSizeMode属性 设置为 AllCells
或:
C# code
dataGridView1.Columns["column1"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
[/Quote]

这个我设置了,可以不起作用,不知是哪给限制住了
xiaohua3006 2012-02-11
  • 打赏
  • 举报
回复
楼上正解~
WAN 2012-02-11
  • 打赏
  • 举报
回复
编辑列... -> 将列的 AutoSizeMode属性 设置为 AllCells
或:
dataGridView1.Columns["column1"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
WAN 2012-02-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ahking 的回复:]
……
那编辑时不能自动根据输入内容长度自动增宽么?
[/Quote]
估计只能自己实现。
稍微试了一下,通过自DataGridView继承新类,并重写ProcessDialogKey,根据单元格内容或输入的keyData计算长度,并调整Column的Width可以做到这种效果
ahking 2012-02-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 foreachif 的回复:]
引用 3 楼 ahking 的回复:
引用 1 楼 foreachif 的回复:

编辑列... -> 将列的 AutoSizeMode属性 设置为 AllCells
或:
C# code
dataGridView1.Columns["column1"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;


这个我设置……
[/Quote]

那编辑时不能自动根据输入内容长度自动增宽么?

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧