需要帮助datagridview选定的列以粗体显示 [英] Need help in datagridview selected column bold

查看:209
本文介绍了需要帮助datagridview选定的列以粗体显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

听到是我的代码

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆