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

查看:456
本文介绍了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中有一列):

Example (DataGridView with one column):

dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Rows.Add("test" + Environment.NewLine + "test"); // Environment.NewLine = "\r\n" in Windows

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

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