[英]How fix width length of cell in Gridview
My code : 我的代码:
DataTable dt = new DataTable();
dt.Columns.Add("#", typeof(string));
dt.Columns.Add("Date", typeof(string));
dt.Columns.Add("OrderID", typeof(string));
dt.Columns.Add("info", typeof(string));
for (int i = 1; i <= 10; i++)
{
dt.Rows.Add(i,"date","OrderID","info")
}
I want to fix width of cell in every Rows of Gridview and when my text is full of width my text will be wrap newline. 我想在Gridview的每一行中固定单元格的宽度,当我的文本充满宽度时,我的文本将换行。 thank you. 谢谢。
In c# winform gridview there WrapMode property that can meet your need 在c#winform gridview中,可以满足您的WrapMode属性
dgvmydgv.DefaultCellStyle.WrapMode =DataGridViewTriState.True;
thus for your case if the gridview is dt then 因此对于您的情况,如果gridview是dt
dt.DefaultCellStle.Wrapmode=DataDataGridViewTriState.True; dt.DefaultCellStle.Wrapmode = DataDataGridViewTriState.True; newline is applied to every texts that exceed the width 换行符适用于所有超过宽度的文本
You also need to set 您还需要设置
DataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
(along with what you have done) for word-wrap to work. (以及您所做的事情)自动换行。
with Wrap Mode To work 使用环绕模式工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.