C#: WinForm系列——DataGridView单元格文本自动换行

DataGridView是.NET开发中常用的控件,在开发中发现大文本数据显示时无法在界面上完全显示,以下是我的解决方法。

(1)首先要保证单元格的为Text类型

(2)在程序中加入以下的代码片段

String str1 = "mac:192.168.0.121";
String str2 = System.Environment.NewLine;
String str3 = "rssi:(-59)";
String mac = str1 +str2 +str3;

//设置自动换行  
this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
//设置自动调整高度  
this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
this.dataGridView1.Rows[0].Cells[0].Value = mac;


猜你喜欢

转载自blog.csdn.net/lidandan2016/article/details/80815565
今日推荐