Thursday, 28 February 2013

Telerik GridViewCheckBoxColumn

There are two major bugs with checkboxes within grids.

The first is that the control doesn't act normally once it's within the grid. 

For example to change its value takes three clicks before the UI changes from unselected to selected:    

  1. the first click selects/sets focus to the grid 
  2. the second click selects/sets focus to the grid 
  3. the third click finally updates the value

This is solved by setting the AutoSelectOnEdit=”True” and EditTriggers=”CellClick”.

Now you hit the second issue, the model still doesn’t update.

To solve this you need to split out the column to use a CellTemplate and DataTemplate containing a CheckBox control with the IsChecked property bound using UpdateSourceTrigger=PropertyChanged.

Example

This example binds to an "IsDefault" property.

What you would expect to work

<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsActive, Mode=TwoWay}" />


What actually works
<telerik:GridViewCheckBoxColumn AutoSelectOnEdit="True"
EditTriggers="CellClick"
DataMemberBinding="{Binding IsActive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }" />

No comments:

Post a Comment