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; } })));
就显示不出字体变色