Refreshing Cell-Formatting at Runtime

3 posts, 1 answers
  1. George C.
    George C. avatar
    23 posts
    Member since:
    Sep 2018

    Posted 24 Dec 2019 Link to this post

    Greetings,

    I have a RadGirdView and a RadColorBox.

    I want to change back/fore colors of each columns of the Radgridview, using the RadColorBox.

    I know that I should use Cell-Formatting of the Radgridview, but the problem is that I can not see (update) the changes at runtime. The cell-formatting does its job only once and that is at the time of starting the program.

     

    Anyway to see the changes at runtime ?

     

    Thanks in advance.

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

    Posted 24 Dec 2019 Link to this post

    Hello, George,     

    Indeed, the CellFormatting event is the appropriate solution for customizing the grid's cells. According to the provided information, I suppose that you use the value of the RadColorBox to change the color used in the CellFormatting event. However, note that once the RadColorBox.Value is changed you need to force firing the CellFormatting event in the grid. This can be achieved by calling the RadGridView.MasterTemplate.Refresh method. 

    I have prepared a sample code snippet for your reference which result is illustrated in the attached gif file: 

            public RadForm1()
            {
                InitializeComponent();
    
                this.radColorBox1.ValueChanged += radColorBox1_ValueChanged;
            }
    
            private void radColorBox1_ValueChanged(object sender, EventArgs e)
            {
                this.radGridView1.MasterTemplate.Refresh();
            }
    
            private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
            {
                if (e.Column.Name == "ProductName")
                {
                    e.CellElement.DrawFill = true;
                    e.CellElement.GradientStyle = GradientStyles.Solid;
                    e.CellElement.BackColor = this.radColorBox1.Value;
                }
                else
                {
                    e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                    e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                    e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                }
            }
    I hope this information helps. If you need any further assistance please don't hesitate to contact me.

     

    Happy Holidays

    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.
  3. George C.
    George C. avatar
    23 posts
    Member since:
    Sep 2018

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

    Exactly.

    This is what I was looking for : RadGridView.MasterTemplate.Refresh

Back to Top