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

How to change the Row selection color in RadgridView for Winforms

2 Answers 1991 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Beatrice
Top achievements
Rank 1
Beatrice asked on 15 Oct 2014, 07:50 PM
Hi,

I have my Radgridview for Winforms (vb.net) with multi-select option.

I have set my code to change the backcolor of the grid based on a criteria.

If CInt(e.RowElement.RowInfo.Cells("trd_typ").Value) = 0 Or CInt(e.RowElement.RowInfo.Cells("trd_typ").Value) = 20 Then
    e.RowElement.DrawFill = True
    e.RowElement.BackColor = Color.LightYellow
ElseIf CInt(e.RowElement.RowInfo.Cells("trd_typ").Value) = 3 Then
     e.RowElement.DrawFill = True
     e.RowElement.BackColor = Color.Gold
End If

It works perfect!

But now when I multi-select the rows it doen't show the color of the selection? Is there a way to have the rows selected to have different color? Atleast I need to differentiate the selected rows.

In the attachment I submitted, I have selected row 2,3 and 4. It just shows the border of the rows little darker. Its very harder to distinguish the color of the selection.

So I just want a color for selecting records and if I unselect it, the color should come back to the original color.

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 16 Oct 2014, 08:24 AM
Hello Beatrice,

Thank you for writing.

In this case you can set different backcolor for the current and the selected rows:
Private Sub radGridView1_ViewRowFormatting(sender As Object, e As RowFormattingEventArgs)
    If e.RowElement.IsSelected OrElse e.RowElement.IsCurrent Then
        e.RowElement.DrawFill = True
        e.RowElement.GradientStyle = GradientStyles.Solid
 
        e.RowElement.BackColor = Color.Gray
    ElseIf Convert.ToInt32(e.RowElement.RowInfo.Cells("trd_typ").Value.ToString()) = 0 OrElse Convert.ToInt32(e.RowElement.RowInfo.Cells("trd_typ").Value.ToString()) = 20 Then
        e.RowElement.DrawFill = True
        e.RowElement.BackColor = Color.LightYellow
    ElseIf Convert.ToInt32(e.RowElement.RowInfo.Cells("trd_typ").Value) = 3 Then
        e.RowElement.DrawFill = True
 
        e.RowElement.BackColor = Color.Gold
    Else
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
        e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
    End If
End Sub

Please note that you should always reset any changed styles. Detailed information can be found here: Formatting Rows.

Let me know if you have additional questions.
 
Regards,
Dimitar
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.

 
0
Beatrice
Top achievements
Rank 1
answered on 21 Oct 2014, 07:08 PM
Thank you Dimitar!
Tags
GridView
Asked by
Beatrice
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Beatrice
Top achievements
Rank 1
Share this question
or