1 Answer, 1 is accepted
Thank you for contacting us.
I suppose that you want to change the BackColor property of a row in RadGridView. If this is what you want to achieve, you can subscribe to the RowFormatting event and change the color. Please take a look at the following code example:
a) subscribe to the RowFormatting event
this
.radGridView1.RowFormatting += radGridView1_RowFormatting;
b) change the color
void
radGridView1_RowFormatting(
object
sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
{
if
((
int
)e.RowElement.RowInfo.Cells[
"MyCount"
].Value == 100)
{
e.RowElement.DrawFill =
true
;
e.RowElement.GradientStyle = GradientStyles.Solid;
e.RowElement.BackColor = Color.GreenYellow;
}
else
{
e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}
In order to prevent applying the formatting to other columns' cell elements all customization should be reset for the rest of the cell elements when use events like ViewCellFormatting, ViewRowFormatting, CellFormatting, RowFormatting.
In our documentation there are articles which demonstrate how you can customize your RadGridView by using the formatting events. You can refer to articles Formatting Rows and Formatting Cells.
I hope this will help. Do not hesitate to write back with further questions.
Ralitsa
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I need to do the same but in VB.net. Used the example you showed as in the documentation but I am getting the following error:
"NullReferenceException"
Can you help me out please?
This is my code:
Private Sub grdSrchResult_RowFormatting(sender As System.Object, e As Telerik.WinControls.UI.RowFormattingEventArgs) Handles grdSrchResult.RowFormatting
If e.RowElement.RowInfo.Cells("STATUS").Value = "Created" Or e.RowElement.RowInfo.Cells("STATUS").Value = "In Production" Then
e.RowElement.DrawFill = True
e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
e.RowElement.BackColor = Color.Red
Else
e.RowElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)
e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local)
e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local)
End If
End Sub
Thank you for contacting us.
I was not able to reproduce the issue using your code. I have attached my sample project used for my tests. Can you please take a look at it and let me know how it differs from your setup? In addition please specify which version of Telerik UI for Winforms you use. Thank you in advance.
I am looking forward to your reply.
Regards,
Ralitsa
Telerik
Thanks for your help.
I got it to work and the issue was not related to the RowFormatting.
thanks,
Lester
Hello.
In my scenario, I don't want to change the default style or a default color of the selected row. Thus it seems to me not right to use Radgridview_RowFormating handler. But in certain conditions, I would like to change the selection color of the specific row.
For example from the SelectionChanged event handler of RadGridView, if a certain condition occurs, I would like to highlight a specific row with a different color.
The problem is that there is no such property like:
myGrid.SelectedItem.Background = Brushes.Red (and I want this to happen only for this specific time, and not always) or
myGrid.Rows[i].Background = Brushes.Red
How can I handle this scenario?
I hope you can help me,
Thanks in advance
Thank you for contacting us.
I am not sure that I fully understand your case. In the you can find sample code and video demonstrating how to change the BackColor of a specific selected row using RowFormatting event and how to use ConditionalFormatting to change the appearance of a row when selecting another row.
If this is not what you want to achieve, I would kindly ask you to send me a more detailed explanation what is your case.
Let me know if I can assist you further.
Regards,
Ralitsa
Telerik