PDA

View Full Version : سوال: انجام CellForamtting در BackgroundWorker



searcher_man
سه شنبه 26 دی 1391, 11:51 صبح
سلام خدمت همه دوستان. همگی خسته نباشید
من برای نمایش اطلاعاتم از RadGridView مربوط به کامپوننت Telerik استفاده می کنم چون امکانات جالبی داره.
با توجه به یک سری شرطها من یکی از سلولها رو با استفاده از رخداد CellFormatting رنگی میکنم، مثلاً هر کدوم با توجه به وضعیتشون سبز، زرد، قرمز و... می شوند. حالا مشکل من اینجاست که وقتی تعداد سطرها زیاد می شود، برنامه من چندثانیه ای به حالت Hang می رود و بعد از چند ثانیه ای اطلاعات را نمایش می دهد، یا زمانی که Scrollbar رو جا به جا می کنم، مقداری کند می شود .
حالا سوال من : چگونه کاری بکنم که رخداد CellFormatting در BackgroundWorker انجام گیرد و به کاربر پیامی مبنی بر Load Data نشان دهم، تا کاربر فکر نکند برنامه هنگ کرده است ؟ یا اگر نیازی به BackgroundWorker نبود، چگونه کاری کنم که قبل از اینکه رخداد CellFormatting اتفاق بیفتد یک فرم نمایش دهد با پیامی مبنی بر اینکه اطلاعات در حالت load است و پس از اتمام کار CellFormatting آن فرم رو ببندم.
من هر چی گشتم چیزی پیدا نکردم، حداقل بدونم کدام رخداد دقیقاً قبل از CellFormatting و کدام رخداد دقیقاً بعد از CellFormatting انجام می شود که من بتوانم یه Loading نمایش دهم.
خواااااااااااهشمند است پاسخ بدید. با تشکر

plus
سه شنبه 26 دی 1391, 12:54 عصر
من با RadGridView کار نکردم ولی اگه از DataGridView مشتق شده باشه و مثل اون کار کنه:
رویداد CellFormatting به ازای هربار رسم یک سلول Raise میشه، در ضمن، توسط خود کنترل DataGridView این رویداد Raise میشه بنابراین در همون Thread فرم اجرا میشه و بعید میدونم راه مناسبی باشه که بشه اون رو توی Background Worker اجرا کرد...کدی که توی CellFormatting نوشته میشه باید تا حد ممکن بهینه باشه، ممکنه کد شما بهینه نباشه اگه میتونید کدتون رو بگذارین.
این رو هم بگم که این کامپوننت های آماده اغلب کمی کد هستن وقتی کارایی مثل کاری که شما میخواین بکنین رو هم بهشون اضافه میکنید همینی میشه که میبینین D-:

searcher_man
سه شنبه 26 دی 1391, 13:34 عصر
با تشکر از پاسختون.
بنده تا جایی که امکان داشته سعی بر این داشتم که کد رو بهینه کنم. حداقل یه راه حل بگید که یه کاری کنم که یک thread دیگر اجرا بشه و پیام Loading رو نمایش بده تا زمانی که کار CellFormatting تموم بشه.

این هم نمونه کد که فرمودید :



private void radGridViewPermitList_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.CellElement.RowInfo.Cells["PermitID"].Value != null)
{
//بهره برداری
if (e.CellElement.ColumnInfo.Name == "PermitID")
{
if (GlobalVar.GlobalPersonalGroupID == 1 || GlobalVar.GlobalPersonalGroupID == 5)
{
string permitid = e.CellElement.RowInfo.Cells["PermitID"].Value.ToString();
this.workflowTableAdapter.Fill(this.permitDataSet. Workflow, permitid);
if (oPTTextBox.Text == "1")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Yellow;
}
if (oPTTextBox.Text == "2")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LimeGreen;
}
if (oPTTextBox.Text == "3")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.CornflowerBlue;
}

if (permitDataSet.Workflow.Rows[0][10].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][7].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Orange;
}
}

if (permitDataSet.Workflow.Rows[0][7].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][9].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.HotPink;
}
}
}

//مهندسی
if (GlobalVar.GlobalPersonalGroupID == 3)
{
string permitid = e.CellElement.RowInfo.Cells["PermitID"].Value.ToString();
this.workflowTableAdapter.Fill(this.permitDataSet. Workflow, permitid);
if (oPTTextBox.Text == "2")
{
if (engTextBox.Text == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightCoral;
}
if (engTextBox.Text == "2")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LimeGreen;
}
if (engTextBox.Text == "1")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Yellow;
}
if (engTextBox.Text == "3")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.CornflowerBlue;
}

if (permitDataSet.Workflow.Rows[0][10].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][7].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Orange;
}
}

if (permitDataSet.Workflow.Rows[0][7].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][8].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.HotPink;
}
}

}
}

//تعمیرات
if (GlobalVar.GlobalPersonalGroupID == 2)
{
string permitid = e.CellElement.RowInfo.Cells["PermitID"].Value.ToString();
this.workflowTableAdapter.Fill(this.permitDataSet. Workflow, permitid);
if (engTextBox.Text == "2")
{
if (mNTTextBox.Text == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightCoral;
}
if (mNTTextBox.Text == "2")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LimeGreen;
}
if (mNTTextBox.Text == "1")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Yellow;
}
if (permitDataSet.Workflow.Rows[0][7].ToString() == "3")
{

e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.CornflowerBlue;
}
if (permitDataSet.Workflow.Rows[0][10].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][7].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Orange;
}
}
}
}
//ایمنی
if (GlobalVar.GlobalPersonalGroupID == 4)
{
string permitid = e.CellElement.RowInfo.Cells["PermitID"].Value.ToString();
this.workflowTableAdapter.Fill(this.permitDataSet. Workflow, permitid);
if (mNTTextBox.Text == "2")
{
if (hSETextBox.Text == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightCoral;
}
if (hSETextBox.Text == "2")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LimeGreen;
}
if (permitDataSet.Workflow.Rows[0][10].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][7].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Orange;
}
}
}
}

//مهندس شیفت
if (GlobalVar.GlobalPersonalGroupID == 5)
{
string permitid = e.CellElement.RowInfo.Cells["PermitID"].Value.ToString();
this.workflowTableAdapter.Fill(this.permitDataSet. Workflow, permitid);
if (hSETextBox.Text == "2")
{
if (shiftEngTextBox.Text == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightCoral;
}
if (shiftEngTextBox.Text == "2")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LimeGreen;
}
if (shiftEngTextBox.Text == "1")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Yellow;
}

if (permitDataSet.Workflow.Rows[0][10].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][7].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Orange;
}
}

if (permitDataSet.Workflow.Rows[0][7].ToString() == "2")
{
if (permitDataSet.Workflow.Rows[0][9].ToString() == "0")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.HotPink;
}
}

}

}

}

}


}


}

plus
سه شنبه 26 دی 1391, 18:44 عصر
شما کاری نیست که در این متد نکرده باشین.این رویداد برای انجام کارهای ساده ای مثل تبدیل مقدار عدد معمولی به فرمت خاص مثل مبلغ و ... استفاده میشه نه برای کاری که شما میکنید.