We are using Telerik 2012.1.412.40 winform controls.
We have following requirement :
In one form , we have Grid View control and there is button called Validate . on click off Validate button , based on some calculations, we need highlight all failed records with RED colour(Entire Row background ) and need to display error message on mouse hove to independent row.
Please guide me in order to achieve above requirement.
Thanks & Regards,
Surya.
5 Answers, 1 is accepted
In order to achieve your requirement, you need to follow the "Formatting cells on demand" section of this article which does virtually the same. The difference is that you need to do this for rows, so you can handle the RowFormatting event:
bool
canFormat =
false
;
void
radGridView1_RowFormatting(
object
sender, RowFormattingEventArgs e)
{
if
(canFormat)
{
// Dummy condition for invalid rows
if
((
int
)e.RowElement.RowInfo.Cells[
"ID"
].Value % 3 == 0)
{
e.RowElement.BackColor = Color.Red;
e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
e.RowElement.DrawFill =
true
;
}
else
{
e.RowElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}
}
private
void
validateButton_Click(
object
sender, EventArgs e)
{
canFormat =
true
;
this
.radGridView1.TableElement.Update(GridUINotifyAction.StateChanged);
}
Further, in order to display error message on mouse hover, you should handle the ToolTipTextNeede as shown below:
void
radGridView1_ToolTipTextNeeded(
object
sender, ToolTipTextNeededEventArgs e)
{
GridDataCellElement dataCell = sender
as
GridDataCellElement;
if
(dataCell !=
null
)
{
// Dummy condition for invalid rows
if
((
int
)dataCell.RowInfo.Cells[
"ID"
].Value % 3 == 0)
{
e.ToolTipText =
"Error!"
;
}
}
}
I hope this helps. Let me know if you have additional questions on this approach.Greetings,
Nikolay
the Telerik team
Thanks for Response.
Your solution is works for me , but one small problem is for zeroth cell background colour is not applying.
Thanks & Regards,
Surya.
Thank you for writing back.
Could you please share more details about your scenario? Which is the cell that you consider as zeroth, and which is the theme that you are using? I am attaching a screenshot of a sample RadGridView that follows my approach, and all cells are red for the appropriate rows. It will be best if you can also send me a screenshot of the cell in question that does not change its color.
Your details will allow me to assist you further.
Nikolay
the Telerik team
Thanks for Response.
We are using Telerik Metro Blue Theme.
Please find attached Screen Shot for your reference.
One more issue i am facing is , when i minimize the application then Red Colour is gone.
Thanks & Regards,
Surya.
I tried to reproduce the experienced issues with Telerik Metro Blue theme, but to no avail. In the sample grid I have even with Telerik Metro Blue all cells are colored red. Moreover, after minimizing and restoring the application the red color still stays in place. Therefore, I would kindly ask you to open a new support ticket and send me a sample application which demonstrates the behavior you describe. This will allow me to provide you with assistance adequate to your feedback.
Thank you for your cooperation.
Nikolay
the Telerik team