posts - 432,  comments - 40,  views - 55万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

试了下边事件无效

private void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)

试了下边事件也无效 (但有的地方可以,有空详细分析下)

复制代码
  /// <summary>
        /// 小计行变颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgv_DataSourceChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                dgv.Rows[i].Cells["单号"].Value.ToString();
                if (dgv.Rows[i].Cells["单号"].Value.ToString().Contains("小计")) //只对小计行进行加粗
                {
                    dgv.Rows[i].DefaultCellStyle.Font =
                           new Font("微软雅黑", 12F, FontStyle.Bold);
                    // dgv.Rows[i].DefaultCellStyle.BackColor = Color.LightCyan;
                }
            }
            dgv.Refresh();
        }
复制代码

 

datagridview控件在显示窗体之前无法更改颜色。 load 事件也不好使.

下边事件可以.

复制代码
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    // Assuming 20 is the column index you're looking for
    if (this.dataGridView2.Columns[e.ColumnIndex].Index == 20)
    {
        if (e.Value != null)
        {
            string strVal = (string)e.Value;
            if (strVal != "")
            {
                e.CellStyle.BackColor = Color.Red;
            }
        }
    }
}
复制代码

 

posted on   小石头的一天  阅读(145)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2021-10-11 ts项目+webpack+juuery 插件的引入
2021-10-11 一个简单的js文件,在ts中使用的方法
2016-10-11 c# 关于取小数点后值四舍五入精度问题
点击右上角即可分享
微信分享提示