首页 新闻 会员 周边

关于datagridview 中的dataGridView1_CellFormatting 事件问题

0
悬赏园豆:10 [已关闭问题] 关闭于 2020-11-09 08:22
 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            try
            {
                var myDgv = sender as DataGridView;
                if (myDgv == null || myDgv.Columns[e.ColumnIndex].Name != "处理状态") return;
                if (e.Value == null) return;
                if (Convert.ToInt32(e.Value) == 2)
                {
                    e.CellStyle.ForeColor = Color.Red;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

想在此事件中使用委托或多线程 都没有办法正常执行的,不能实现

如:

   ThreadPool.QueueUserWorkItem(
               state =>
                   BeginInvoke(new Action(() =>
                   {
                       var myDgv = sender as DataGridView;
                       if (myDgv == null || myDgv.Columns[e.ColumnIndex].Name != "处理状态") return;
                       if (e.Value == null) return;
                       if (Convert.ToInt32(e.Value) == 2)
                       {
                           e.CellStyle.ForeColor = Color.Red;
                       }
                   })));

 

就显示不出字体变色

王力之的主页 王力之 | 初学一级 | 园豆:38
提问于:2015-06-21 12:19
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册