Are there any performance implications of rendering a button using CellFormatting event of RadGridView

1 Answer 50 Views
GridView
Ruslan
Top achievements
Rank 1
Iron
Ruslan asked on 12 Nov 2024, 12:56 AM
Hello,

I have code similar to this


private void OnCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (/*some-condition-that-are-always-true-for-all-cells-in-specific-column*/true)
    {
        e.CellElement.Children.Clear();
        e.CellElement.Children.Add(new RadButtonElement { Text = e.CellElement.Value?.ToString() });
    }
}

So basically, what I'm trying to achieve is to make GridViewDataColumn look and behave like GridViewCommandColumn (currently I handle clicks on the button inside cells CellClick event handler)


My questions are:
  1. Are there any performance drawbacks of mine implementation (i.e., related to the fact that the cell formatting event could be fired very often) ?
  2. Is there a way to dynamically change grid column types. For example, after data binding, a column becomes a GridViewDataColumn but after clicking a button somewhere in a form it changes to GridViewCommandColumn?
 
Thanks

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Nov 2024, 10:17 AM

Hello Ruslan,

In general, modifying the cells in the CellFormatting event should not lead to performance problems. However, in your case, I don't think that populating the Children's collection of the control in the CellFormatting event will be a good approach. The cells inside the control are reused due to the built-in RadGridView virtualization mechanism. You will always need to clear the collection, otherwise, other cells will contain the button during scroll. 

For the first approach, I would suggest creating custom cells as demonstrated in the Creating custom cells help article. You can follow the steps in the article and design your cell per your requirements. 

For the second question, I would suggest adding two columns and hiding and showing them depending on your scenario. For example, you can show the GridViewDataColumn, while the GridViewCommandColumn is hidden. Then while clicking a button, you can hide the first one and show the second one. To hide/show a RadGridView column, you can use its IsVisible property.

I hope that you find my reply helpful.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Ruslan
Top achievements
Rank 1
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or