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
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!
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
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 >>
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