The following code to make the headers bold in a RadGridView. After upgrading to different 2022 versions from 2021, this code causes a Parameter is not valid error in ((System.ComponentModel.ISupportInitialize)(this.RadGridView1.MasterTemplate)).EndInit();
If I comment out the code and run then there is no error generated.
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridHeaderCellElement)
{
e.CellElement.Font = myCustomFont;
}
}
This has solved my problem. As you suggested, creating the font once and using the variable within the event handler was the solution. This was an older project I was upgrading to 2022, when the issue arose.
Thank you
Hello, Paul,
Please have in mind that the CellFormatting event is expected to be fired many times to ensure that the correct style settings are applied to the grid cell elements. Creating a font is a time-consuming operation which is not recommended to be executed multiple times. You should create the font just once and use the variable in the event handler like it is demonstrated below. Make sure that the font is reset for the rest of the cells:
Font myCustomFont = new Font("Arial", 10f, FontStyle.Bold);
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement is GridHeaderCellElement)
{
e.CellElement.Font = myCustomFont;
}
else
{
e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
}
}
Following the provided information, I was unable to reproduce the issue you are facing. Please refer to the attached gif file illustrating the behavior on my end with the specified version.
I have attached my sample project. Please give it a try and see how it works on your end. Am I missing something? Could you please specify the exact steps how to reproduce the problem? Feel free to modify the project in a way to reproduce the experienced issue and get back to me with it so I can investigate the precise case. Thank you in advance.
I am looking forward to your reply.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.