DataGridView中在新增行时怎样设置每个Cell单元格的字体样式

大憨熊 提交于 2019-12-02 22:35:35

场景

DataGridView怎样实现添加、删除、上移、下移一行:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102814145

在上面中应用到了新增一行时如果对某个单元格中的字体大小、是否加粗、字体居中显示等有要求,要怎样设置。

注:

博客主页:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

 

           DataGridViewRow dr = new DataGridViewRow();
            dr.CreateCells(this.dataGridView_Task_ViewEdit);
            //第一个单元格不赋值
            //dr.Cells[0].Value = "1111";

            dr.Cells[1].Value = "步_" + (this.dataGridView_Task_ViewEdit.Rows.Count + 1).ToString();

            Font font = new Font("宋体",14,FontStyle.Bold);
            dr.Cells[2].Style.Font = font;
            dr.Cells[2].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dr.Cells[2].Value = "搁置";

            dr.Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dr.Cells[3].Value = "步时间>0.000秒 下一步";

            dr.Cells[4].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dr.Cells[4].Value = "时间>1.000秒";

            dr.Cells[5].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dr.Cells[5].Value = "低";

            dr.Cells[6].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dr.Cells[6].Value = "0";

            this.dataGridView_Task_ViewEdit.Rows.Add(dr);//添加的行作为最后一行

 

效果

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!