需要帮助datagridview选定的列以粗体显示 [英] Need help in datagridview selected column bold
问题描述
大家好,
听到是我的代码
private void SetFormatting()
private void SetFormatting()
{
{
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.Font =新的Font("Verdana",10,FontStyle.Bold);
columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
this.dgPO.Columns ["TotalKG"].DefaultCellStyle = columnHeaderStyle;
this.dgPO.Columns["TotalKG"].DefaultCellStyle = columnHeaderStyle;
}
}
此代码无法正常工作,请帮助我解决此代码
this code will not work please help me on this code
Hitesh Patel
Hitesh Patel
推荐答案
我希望您正在使用Databound gridview.即(从表中加载的值).如果这样做,则会出现异常,因为未将"TotalKG"列手动添加到gridview中,所以程序无法找到列名,这将导致 错误.为避免错误,请使用如下代码所示的索引值
I hope that you are using Databound gridview. i.e (values loaded from table). if you are doing so then you will get the exception, since the column 'TotalKG' is not added manually to the gridview, the program cannot find the column name, which is causing the error.In order to avoid the error, use the index value as shown below code
private void SetFormatting()
{
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
Font f=new Font("Verdana", 10, FontStyle.Bold);
this.dgPO.Columns[1].DefaultCellStyle = columnHeaderStyle;
}
这篇关于需要帮助datagridview选定的列以粗体显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!