PDA

View Full Version : سوال: مشکل در رنگ آمیزی ردیف ها در RadGridView



NasimBamdad
چهارشنبه 28 خرداد 1393, 14:48 عصر
سلام و خسته نباشید

مدتی است می خوام گریدم رو رنگ آمیزی کنم اما مشکل دارم .

می خوام طوری باشه که اگه یک فیلدم ( Stock ) مثلا برابر 0 بود اون ردیف رو قرمز کنه .

فیلد Stock فیلد موجودی هست و می خوام وقتی فیلد برابر 0 بود ، اون ردیف رو BackColor اش رو قرمز کنیم

rezaei_y
چهارشنبه 28 خرداد 1393, 15:02 عصر
بعد از پر کردن دیتاگرید ویو این کد رو فراخوانی کن


foreach (DataGridViewRow row in mydgv.Rows)
{
if(row.Cells[Stock].value.tostring()=="0")
row.Style.BackColor =System.Drawing.Color.Red;
}

NasimBamdad
چهارشنبه 28 خرداد 1393, 15:05 عصر
برای گرید Telerik جواب نمیده متاسفانه

Cannot convert type 'Telerik.WinControls.UI.GridViewRowInfo' to 'System.Windows.Forms.DataGridViewRow'




'System.Windows.Forms.DataGridViewRow' does not contain a definition for 'Style' and no extension method 'Style' accepting a first argument of type 'System.Windows.Forms.DataGridViewRow' could be found (are you missing a using directive or an assembly reference?)

mehrdad.ghorbaniyan
چهارشنبه 28 خرداد 1393, 15:18 عصر
من هم قبلا این مشکلو داشتم.هر کاری کردم نشد گرید ویرو کامپوننت Telerik.اما گرید ویو خود سی شارپ میشه

khokhan
چهارشنبه 28 خرداد 1393, 15:45 عصر
برای گرید Telerik جواب نمیده متاسفانه

Cannot convert type 'Telerik.WinControls.UI.GridViewRowInfo' to 'System.Windows.Forms.DataGridViewRow'




'System.Windows.Forms.DataGridViewRow' does not contain a definition for 'Style' and no extension method 'Style' accepting a first argument of type 'System.Windows.Forms.DataGridViewRow' could be found (are you missing a using directive or an assembly reference?)




کنترلradGridView کامپوننت Telerik ، یه رویداد داره به نام ViewRowFormatting که می تونین ردیف یا سلول خاصی رو بر اساس شرط خاصی رنگ آمیزی کنی


void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
Console.WriteLine(e.RowElement.GetType());
if (e.RowElement is GridTableHeaderRowElement)
{
e.RowElement.DrawFill = true;
e.RowElement.BackColor = Color.Navy;
e.RowElement.NumberOfColors = 1;
e.RowElement.ForeColor = Color.White;
}
else
{
e.RowElement.ResetValue(LightVisualElement.DrawFil lProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.BackCol orProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.NumberO fColorsProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.ForeCol orProperty, ValueResetFlags.Local);
}
}

ویا اینکه در رویداد RowFormatting بنویسین اینطوری :


private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
if ((bool)e.RowElement.RowInfo.Cells["BMP"].Value == true)
{
e.RowElement.DrawFill = true;
e.RowElement.GradientStyle = GradientStyles.Solid;
e.RowElement.BackColor = Color.Aqua;
}
else
{
e.RowElement.ResetValue(LightVisualElement.BackCol orProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.Gradien tStyleProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.DrawFil lProperty, ValueResetFlags.Local);
}
}

تبسم ساینا
چهارشنبه 12 فروردین 1394, 06:00 صبح
سلام .. چجوری میشه این کد ها رو برد تو یه تابع و صداش زد؟
مثلا" من اینو نوشتم و میخوام صداش بزنم چی رو بفرستم به تابع ؟
private void ColoringChanged(RowFormattingEventArgs e) {
e.RowElement.DrawFill = true;
e.RowElement.BackColor = Color.White;


ConnectionStringCheck connectionStringCheck = new ConnectionStringCheck(e.RowElement.RowInfo.Cells["ItemName"].Value.ToString() + "master");
connectionStringCheck.DbConnectionSet();
if (!connectionStringCheck.IsDbConnected)
{
e.RowElement.ForeColor = Color.Red;
return;
}


if (!(bool)e.RowElement.RowInfo.Cells["Included"].Value)
{
e.RowElement.ForeColor = Color.Orchid;
return;
}


e.RowElement.ResetValue(LightVisualElement.BackCol orProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.Gradien tStyleProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.DrawFil lProperty, ValueResetFlags.Local);
}