C#:DataGridView控件中的多行文本 [英] C#: multiline text in DataGridView control

查看:127
本文介绍了C#:DataGridView控件中的多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataGridView控件是否可以在单元格中显示多行文本?

Is it possible for the DataGridView control to display multiline text in a cell?

我使用的是Visual Studio 2005和C#。

I am using Visual Studio 2005 and C#.

推荐答案

您应该将 DefaultCellStyle.WrapMode 列的属性设置为 DataGridViewTriState.True 。单元格中的文本将被正确显示。

You should set DefaultCellStyle.WrapMode property of column to DataGridViewTriState.True. After that text in cells will be displayed correctly.

示例( DataGridView 与一列):

dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Rows.Add("test" + Environment.NewLine + "test");

Environment.NewLine = \r\\\
在Windows)

(Environment.NewLine = \r\n in Windows)

这篇关于C#:DataGridView控件中的多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆