马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

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

[复制链接]
查看3010 | 回复1 | 2019-11-8 09:53:15 | 显示全部楼层 |阅读模式

场景

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

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

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

注:

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

实现

  1. DataGridViewRow dr = new DataGridViewRow();
  2. dr.CreateCells(this.dataGridView_Task_ViewEdit);
  3. //第一个单元格不赋值
  4. //dr.Cells[0].Value = "1111";
  5. dr.Cells[1].Value = "步_" + (this.dataGridView_Task_ViewEdit.Rows.Count + 1).ToString();
  6. Font font = new Font("宋体",14,FontStyle.Bold);
  7. dr.Cells[2].Style.Font = font;
  8. dr.Cells[2].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  9. dr.Cells[2].Value = "搁置";
  10. dr.Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  11. dr.Cells[3].Value = "步时间>0.000秒 下一步";
  12. dr.Cells[4].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  13. dr.Cells[4].Value = "时间>1.000秒";
  14. dr.Cells[5].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  15. dr.Cells[5].Value = "低";
  16. dr.Cells[6].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  17. dr.Cells[6].Value = "0";
  18. this.dataGridView_Task_ViewEdit.Rows.Add(dr);//添加的行作为末了一行
复制代码

效果

095614ljz2ya8thax0jxup.jpg

C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则