[英]Changing width of a column from gridview
I with this code marking the first column from DataGridView
:我用这段代码标记了
DataGridView
的第一列:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
}
but because the low width, the numbers are not shown properly, how can I change the width the first column ?但是由于宽度较低,数字显示不正确,我该如何更改第一列的宽度?
Image:图片:
you need to handle the OnRowDataBound event of your gridview.您需要处理 gridview 的 OnRowDataBound 事件。
protected void dataGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[YourColumnIndex].With = YourValue;
}
}
You have to set an appropriate DataGridViewRowHeadersWidthSizeMode
value to RowHeadersWidthSizeMode
.您必须将适当的
DataGridViewRowHeadersWidthSizeMode
值设置为RowHeadersWidthSizeMode
。
For example:例如:
dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.