}
C#中DataGridView的标题和宽度设置
原创
©著作权归作者所有:来自51CTO博客作者zw20045的原创作品,请联系作者获取转载授权,否则将追究法律责任
private void SetDataGridStylesFromNet(string strFlag, DataTable dtableTemp, DataGridView dataGridView)
{
if (strFlag == "老化类")
{//商品信息
int[] iArrayWidth = {180,100,200,80,60,
150,150,150,150
};
string[] strArrayText = { "条形码","产品代码","产品名称","规格型号","单位"
,"开始时间","结束时间","总耗时间","操作人"
};
string[] strArrayZiduanMapping = { "FMainBarCode","FNumber","ItemName","FModel","FUnitName"
,"FStartTime","FEndTime","IntervalTime","UserName"
};
//将DataTable绑定到DataView中
dataGridView.Columns.Clear();
dataGridView.AutoGenerateColumns = false;
//绑定DataView到dataGridView上
dataGridView.DataSource = dtableTemp;
for (int i = 0; i < iArrayWidth.Length; i++)
{
DataGridViewTextBoxColumn dataGridViewClolumnTemp = new DataGridViewTextBoxColumn();
dataGridViewClolumnTemp.DataPropertyName = strArrayZiduanMapping[i];
dataGridViewClolumnTemp.HeaderText = strArrayText[i];
dataGridViewClolumnTemp.Width = iArrayWidth[i];
dataGridView.Columns.Add(dataGridViewClolumnTemp);//最后一定要添加进去
}
return;
}
}
}
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
win7添加宽带连接
添加宽带连接
宽带连接