How to change the Row selection color in RadgridView for Winforms

3 posts, 1 answers
  1. Beatrice
    Beatrice avatar
    10 posts
    Member since:
    Jun 2014

    Posted 15 Oct 2014 Link to this post

    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. Answer
    Dimitar
    Admin
    Dimitar avatar
    2654 posts

    Posted 16 Oct 2014 Link to this post

    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.

     
  3. Beatrice
    Beatrice avatar
    10 posts
    Member since:
    Jun 2014

    Posted 21 Oct 2014 in reply to Dimitar Link to this post

    Thank you Dimitar!
Back to Top