Highlight the selected row

5 posts, 0 answers
  1. Frank
    Frank avatar
    95 posts
    Member since:
    Mar 2012

    Posted 23 Dec 2016 Link to this post

    When I add the code

    private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
    {
        if ((bool)e.RowElement.RowInfo.Cells["BMP"].Value == true)
        {
            e.RowElement.DrawFill = true;
            e.RowElement.GradientStyle = GradientStyles.Solid;
            e.RowElement.BackColor = Color.Aqua;
        }
        else
        {
            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        }
    }

     

    It will change the background color in the grid as expected.  But now when I select a row it only highlights the cell I selected and then outlines the rest of the row.  How can I get it to highlight the entire cell like it does on the rows the are the else row.

     

     

  2. Dess
    Admin
    Dess avatar
    2050 posts

    Posted 26 Dec 2016 Link to this post

    Hello Frank,

    Thank you for writing.  

    Depending on the applied theme, the grid's style may be defined either at row level or at cell level. That is why it is recommended to use the CellFormatting event in order to obtain the desired color when the row is selected. Additional information for this event is available here: http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Frank
    Frank avatar
    95 posts
    Member since:
    Mar 2012

    Posted 27 Dec 2016 in reply to Dess Link to this post

    ok well that answered nothing.  I changed to use the cellFormatting Event and it is even worse.

    The default of the grid is alternating color.  Then I look at a date in one of the columns and if it is past then I change the backgound to pink, if it is within 5 days I make it yellow and if non of the above then it stays the normal alternating color.  This works fine.

     

    The issue is when I click a row, it it did not get a custom back color it highlights properly. If it got a custom color it only outlines the row.  I assume there must be some way on the SelectChange event I could set the row to be highlighted and override the cuetome back color.  Then when another row is selected it will go back to the custom color and then highlight the row I have selected.

  4. Frank
    Frank avatar
    95 posts
    Member since:
    Mar 2012

    Posted 27 Dec 2016 in reply to Frank Link to this post

    Ah I got it.

    I added

    if (e.RowElement.RowInfo.IsCurrent)
                {
                    e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                }
                else
                {

     

    around my current RowFormatting event and it worked

     

  5. Dess
    Admin
    Dess avatar
    2050 posts

    Posted 28 Dec 2016 Link to this post

    Hello Frank,

    Thank you for writing.  

    Due to the UI virtualization in RadGridView, cell/row elements are created only for currently visible cells/rows and are being reused during operations like scrolling, filtering, grouping and so on. In order to prevent applying the formatting to other columns' cell elements (because of the cell/row reuse) all customization should be reset for the rest of the cell/row elements. It is demonstrated how to reset the applied style in the following help articles:

    http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells
    http://docs.telerik.com/devtools/winforms/gridview/rows/formatting-rows

    If you experience any further difficulties it would be greatly appreciated if you can provide a sample project demonstrating the undesired behavior. Thus, we would be able to investigate the precise case and assist you further. Thank you. 

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top