Reset cell format

6 posts, 1 answers
  1. Amige
    Amige avatar
    52 posts
    Member since:
    Dec 2013

    Posted 05 Jul 2017 Link to this post

    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

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3624 posts

    Posted 06 Jul 2017 Link to this post

    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.
  3. Amige
    Amige avatar
    52 posts
    Member since:
    Dec 2013

    Posted 06 Jul 2017 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello Dess,

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

    Regards,

    Alberto

  4. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 15 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess

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

  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3624 posts

    Posted 15 Dec 2019 Link to this post

    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.
  6. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 16 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    I appreciate your assistance
Back to Top