当前位置:编程学习 > C#/ASP.NET >>

datagridview_CellFormattring 函数占用内存50+,什么原因?

RT。代码如下,当我注释掉这段后CPU占用率就正常了,就是这个函数出的问题。大家帮我看看是什么原因。

private void 
dgvBudget_CellFormatting(object sender, DataGridViewCellFormattingEventArgs 
e)
{
if (e != null && e.RowIndex > 
-1)
{
DataGridViewRow dr = 
this.dgvBudget.Rows[e.RowIndex];
double x = 
Convert.ToDouble(dr.Cells["本月累计支出"].Value);
double y = 
Convert.ToDouble(dr.Cells["预警值"].Value);
double z = 
Convert.ToDouble(dr.Cells["本月预算"].Value);
if (x>=y) 
dr.DefaultCellStyle.ForeColor = Color.Yellow;
if (x >= z) 
dr.DefaultCellStyle.ForeColor = Color.Red;
}

后面我自己写了个函数设置单元格颜色。不占CPU
private void dgvBudget_ColorSet() { if (dgvBudget.Rows.Count>0) { for (int i = 0; i <dgvBudget.Rows.Count; i++) { //MessageBox.Show(dgvBudget.Rows[i].Cells["本月累计支出"].Value.ToString()); double x = Convert.ToDouble(dgvBudget.Rows[i].Cells["本月累计支出"].Value.ToString()); double y = Convert.ToDouble(dgvBudget.Rows[i].Cells["预警值"].Value.ToString()); double z = Convert.ToDouble(dgvBudget.Rows[i].Cells["本月预算"].Value.ToString()); if (x >= y) dgvBudget.Rows[i].DefaultCellStyle.ForeColor = Color.Yellow; if (x >= z) dgvBudget.Rows[i].DefaultCellStyle.ForeColor = Color.Red; dgvBudget.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } } }
c# winform datagridview CPU 函数 --------------------编程问答-------------------- 我以为是这个,加上也还是占CPU
.Convert.ToDouble(dr.Cells["本月累计支出"].Value.ToString());
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,