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

Reset cell format

5 Answers 479 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amige
Top achievements
Rank 1
Veteran
Amige asked on 05 Jul 2017, 06:50 PM

I have a GridView where I am changing the cell BackColor when the value is changed:

 

void TelerikGridView_CellValueChanged(object sender, GridViewCellEventArgs e)
        {           
               
                    if (e.Row.Tag == null)
                        e.Row.Tag = e.Column.Name;
 
                    if (!e.Row.Tag.ToString().Contains(e.Column.Name))
                        e.Row.Tag += e.Column.Name;
                
        }

 

void TelerikGridView_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.Row.Tag != null && e.Row.Tag.ToString().Contains(e.Column.Name))
            {
               
                    e.CellElement.DrawFill = true;
                    e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                    e.CellElement.BackColor = Color.Red;
              
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }

 

This is working as expected, now I want to add a "Reset" button, when I click on it I would like to reset or remove the format of all the cells that have been changed, how can I accomplish this?

 

Regards,

Alberto

5 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Jul 2017, 10:09 AM
Hello Amige, 

Thank you for writing.  

The CellFormatting event is the appropriate place to customize grid cells according to some custom criteria. If you need to reset all styles that are already applied, it is necessary to clear the Tag property for all the rows. Then, in order to force the CellFormatting event to be fired and apply the correct style, you can call the Refresh method of the MasterTemplate.

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

Regards,
Dess
Progress Telerik
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
Amige
Top achievements
Rank 1
Veteran
answered on 06 Jul 2017, 03:48 PM

Hello Dess,

Thanks for your answer. That's what I needed.

Regards,

Alberto

0
Aseman
Top achievements
Rank 1
Veteran
answered on 15 Dec 2019, 07:41 AM

Hi Dess

what does "e.CellElement.ResetValue" Do Exactly?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Dec 2019, 05:54 AM

Hello, Aseman,    

Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells 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 reuse), all customization should be reset for the rest of the cell elements which actually the GridViewCellEventArgs .CellElement.ResetValue method does. 

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Aseman
Top achievements
Rank 1
Veteran
answered on 16 Dec 2019, 07:05 AM
I appreciate your assistance
Tags
GridView
Asked by
Amige
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Amige
Top achievements
Rank 1
Veteran
Aseman
Top achievements
Rank 1
Veteran
Share this question
or