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

Change Rad Girdview Row Background Color after Data bind

5 Answers 302 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Surya
Top achievements
Rank 1
Surya asked on 05 Sep 2012, 06:44 PM
Hi,

 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

Sort by
0
Accepted
Nikolay
Telerik team
answered on 06 Sep 2012, 01:55 PM
Hello Surya,

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
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Surya
Top achievements
Rank 1
answered on 06 Sep 2012, 06:15 PM
Hi Nikolay ,

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.
0
Nikolay
Telerik team
answered on 10 Sep 2012, 08:45 AM
Hi 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.

Greetings,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Surya
Top achievements
Rank 1
answered on 10 Sep 2012, 09:19 AM
Hi 

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.
0
Nikolay
Telerik team
answered on 10 Sep 2012, 01:56 PM
Hello 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.

All the best,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Surya
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Surya
Top achievements
Rank 1
Share this question
or