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

Highlight the selected row

4 Answers 581 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 23 Dec 2016, 06:47 PM

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.

 

 

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Dec 2016, 11:22 AM
Hello Frank,

Thank you for writing.  

Depending on the applied theme, the grid's style may be defined either at row level or at 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.
0
Frank
Top achievements
Rank 1
answered on 27 Dec 2016, 09:24 PM

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.

0
Frank
Top achievements
Rank 1
answered on 27 Dec 2016, 09:34 PM

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

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Dec 2016, 12:19 PM
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.
Tags
GridView
Asked by
Frank
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Frank
Top achievements
Rank 1
Share this question
or