This is a migrated thread and some comments may be shown as answers.

formatting row in hierarchical RadGridView

4 Answers 95 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mauro
Top achievements
Rank 1
mauro asked on 26 Jul 2011, 04:49 PM

Hello all,
I am using a hierarchical RadGridView with 3-level and I would like that the rows of 2nd level and the rows of 3rd level that meet a search criteria (such as the Notes column contains the value "perizia") appear with a different backcolor.
I have used, as described in the manual online, the event radGridView_RowFormatting (object sender, RowFormattingEventArgs e) but while I scroll the ChildRows collection I lose the information about the class Telerik.WinControls.UI.GridDataRowElement essential to allow formatting the row read.
How can I do to get this highlighting ?

Best regards,
Mauro Fiore

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 29 Jul 2011, 12:31 PM
Hello Mauro,

Thank you for this question. RadGridView uses virtualization for its UI elements and creates visual elements only for the rows and cells that are currently visible. When scrolling it reuses these elements for other data rows and cells. That is why you should use the RowElement property only within the RowFormatting event. Here is a sample:
void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    object idValue = e.RowElement.RowInfo.Cells["ID"].Value;
    if (idValue != null && idValue != DBNull.Value && (int)idValue > 3)
    {
        e.RowElement.DrawFill = true;
        e.RowElement.GradientStyle = GradientStyles.Solid;
        e.RowElement.BackColor = Color.Yellow;
    }
    else
    {
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    }
}

In case you need further assistance with this, please send us your application and describe the desired behavior. We will be glad to help further.

Do not hesitate to contact me, if you have other questions.
 
Greetings,
Jack
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
mauro
Top achievements
Rank 1
answered on 29 Jul 2011, 05:01 PM

Hello Jack,
first of all thanks, now in your answer I think you notify me that only during the scrolling the rows can be formatted, so, in my bad English, I try to explain you what is my intention. To help the end user I would like that: if a value in a row at the 3rd level of a radgridview meets the condition "IdValue> 3", the same row and the parent row (2nd level) should to be displayed with a marked background. Everything must be controlled before that the radgridview display the data and maybe not after (note I'm using Telerik products from about 10 days and do not know if the above conditional control can be do through an event). The example proposed by you, and here I am mistaken, only works for rows of the lower level but not for higher levels (as if it were a simple gridview). I await a your reply.

Kind regards,
Mauro Fiore

0
Martin Vasilev
Telerik team
answered on 03 Aug 2011, 04:53 PM
Hello Mauro,

Thank you for writing.

The RowFormatting event fires for every visible row in RadGridView, regardless of its level. In the described scenario you can use ChildRows collection to check if the condition is met for the second level of hierarchy. Please consider the following code as an example:
void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            if (e.RowElement.ViewTemplate == this.radGridView1.Templates[0])
            {
                foreach (var childRow in e.RowElement.RowInfo.ChildRows)
                {
                    if ((decimal)childRow.Cells["UnitPrice"].Value > 50)
                    {
                        e.RowElement.DrawFill = true;
                        e.RowElement.NumberOfColors = 1;
                        e.RowElement.BackColor = Color.Yellow;
                        break;
                    }
                }
            }
            else if (e.RowElement.ViewTemplate == this.radGridView1.Templates[0].Templates[0]
                && (decimal)e.RowElement.RowInfo.Cells["UnitPrice"].Value > 50)
            {
                e.RowElement.DrawFill = true;
                e.RowElement.NumberOfColors = 1;
                e.RowElement.BackColor = Color.Yellow;
            }
            else
            {
                e.RowElement.ResetValue(GridRowElement.DrawFillProperty, ValueResetFlags.Local);
                e.RowElement.ResetValue(GridRowElement.NumberOfColorsProperty, ValueResetFlags.Local);
                e.RowElement.ResetValue(GridRowElement.BackColorProperty, ValueResetFlags.Local);
            }
        }

I am also attaching a small sample project, which demonstrates this approach. Hope this will be helpful. Let me know if you have any additional questions.

Regards,
Martin Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
mauro
Top achievements
Rank 1
answered on 16 Aug 2011, 09:37 AM
Hello Martin
forgive the length of time in responding but I'm back at work today after the summer holidays. First of all thank you for the answer I've provided and will update my software as soon as I can. Thanks again and good day

Best regards,
Mauro
Tags
GridView
Asked by
mauro
Top achievements
Rank 1
Answers by
Jack
Telerik team
mauro
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or