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

Refreshing Cell-Formatting at Runtime

2 Answers 1232 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George C.
Top achievements
Rank 2
Iron
Veteran
George C. asked on 24 Dec 2019, 11:21 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Dec 2019, 11:51 AM

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.
0
George C.
Top achievements
Rank 2
Iron
Veteran
answered on 24 Dec 2019, 12:20 PM

Exactly.

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

Tags
GridView
Asked by
George C.
Top achievements
Rank 2
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
George C.
Top achievements
Rank 2
Iron
Veteran
Share this question
or