Telerik RagGridView – Where Are My Cells Gone?

My latest application required a RadGridView having a dynamic number of columns. And therefor, the binding of the data an event handler needed to by managed during runtime as well.

Not really in issue: handle the RowLoaded event, iterate over the cells of the row passed by the event arguments, and everything is fine. That’s what I thought and implemented.

It was fine until the number of rows to be displayed exceeded the number of rows that could be displayed. When starting to scroll the grid in the UI, an exception occurred (in this case, the browser windows turned white and the status bar mentioned there was an error on the page – really helpful!)

So I had to start the debugger, and immediately I saw what caused the exception: the number of cells in the row passed to the event handler was smaller than the number of columns of the grid. Since I iterated over the number of columns of the grid, and then used the index to access the corresponding cell of the row, it has to fail.

Soon it was obvious that the number of cells in the row matched the number of columns displayed in the browser. But where have all the other cells gone? The answer to this question is UI Virtualization, explained in this article:

After reading the article, the solution was quite easy: turn of the column virtualization of the grid, and the number of cells in the row passed to the handler was matching to the number of columns of the grid.

I think it’s worth to mention that during the initial loading of the grid, all rows had the matching number of cells in the RowLoaded-handler, even with UI virtualization turned on. The mismatch only occurred when the user started to scroll.

Silverlight, Telerik GridView, Dynamically Created Loaded Handler & Performance

I like Silverlight, Telerik’s GridView control and the ability to create the columns of a grid dynamically.

Recently, I had to build up a grid during runtime. The number of columns and the header text is unknown at design time (read it from the database), but nothing to worry about. The XAML file only contains the definition of the Telerik grid control itself, but no column definitions.

Almost every column should contain a checkbox. And I need to handle the load event of every dynamically created checkox. Since I had to use Silverlight 4, I needed to create the cell template by using the XamlReader loading a XAML fragment.

To verify that the creation of the grid columns works at all, I did not include the load event handling in the XAML fragment for the first try. The application started, the grid and its columns were built as expected. Everything was fine.

Then I added the event handler to the fragment . The result contains something like this: <CheckBox Loaded="MyCheckBoxLoadedHandlerMethod"/>.

Having this little change done, opening the view containing the grid hangs in that way, that after a while IE complained the localhost was not responding any more. CPU usage went up, and memory consumption too.

What I think what happened is, that for each checkbox in the grid (in my sample 17 lines by 14 checkbox columns), an event handler instance is created either by Silverlight or the Telerik control. This seems to be such resource intensive, that it brought down IE.

Now what I had to do is to create a single event handler instance and assign it to every newly created checkbox. But how can I do that in Silverlight 4? In Silverlight 4 you cannot assign an object to a DataTemplate, except using the XamlReader approach (Silverlight 5 offers this ability).

I added a RowLoaded event handler to the grid. The handler iterates thru the cells of the row and looks for the checkbox child element. If it finds one, the one-and-only handler is assigned to the Click event.

It still takes time to show up the view, but now it works. I can’t tell what the real reason for the slowdown of the first approach is. But I found a way to get it running 🙂

Silverlight’s DatePicker and Telerik’s RadWindow Dialog

In my current Silverlight project, I’m using the DatePicker control, which is part of the Silverlight SDK.

In one scenario, the DatePicker with TwoWay binding is embedded into a User Control, which itself is embedded into another User Control. The format is “dd.MM.yyyy”. Entering e.g. 23.11.2011 works fine, means the value of the bound property is set to the 23rd of November in 2011.

Then I needed a date input inside of a modal dialog. Shouldn’t be a problem, so I just copied and pasted the XAML from the User Control into the dialog’s XAML. But entering 23.11.2011 in the dialog, the bound property remains null. First I thought there was a binding issue at all, but after some playing around I noticed that entering 8.11.2011 worked fine. The bound property was set correctly to the 8th of November 2011. But as soon as the entered day was bigger than 12 – the maximum value of a month – the input was ignored.

Luckily, I already had a DateConverter created in that project. This converter parses the entered string in the ConvertBack method using the current culture. So I bound the DatePicker control to that converter too, set a breakpoint at the ConvertBack method, and stepped into it. And to my surprise, the entered values was interpreted and bound correctly now.

To me, the behavior does not make sense. Why does the Date Picker control act different in these two scenarios? One thing might be that the RadWindow as the parent somehow changes the culture. But from my understanding, this should lead to the 11th of August 2011 when entering 8.11.2011.

At least I’m happy that I found a workaround. I do not have to understand everything at all…

Disable Control-Buttons of RadGridView

Using Telerik’s RadGridView, one can connect the add, update, cancel and delete command to RadButtons by setting the


properties of the buttons and link to the grid by setting the

CommandTarget="{Binding ElementName=GridViewName}"


For some reasons, I needed to disable the buttons, depending on the rights the currently logged in user has. Setting

button.IsEnabled = false;

during runtime did not work, for whatever reasons. But setting


during runtime, without disabling the button, worked fine. Resetting the button’s CommandTarget to the associated RadGridView re-enabled the button.

I tend to call this a bug. Luckily, there is an easy work around.