Friday, April 26, 2013

Checkbox on datagrid with single click.

It is quite common to use checkbox in a datagrid. To make our lives easier the WPF DataGrid has a class called DataGridCheckBoxColumn to easily add a column in your datagrid a checkbox column format. However, this class has a drawback behavior that makes the user have to click twice on the checkbox inside the datagrid to select it. Unfortunately there is no property (up to the moment of publishing this post) that makes this boring behavior abolished.
But all is not lost, you'll see in this minipost with few lines of code how you can customize your datagrid to create a column that contains checkbox to be selected with a single click!

The code shown here is the same post that treate about datagrid with collapsible rows (see it here).
We solve this "problem" modifying the template column of datagrid where we want to put our checkbox, inserting a checkbox directly in the cell, as shown in the code below:
<DataGridTemplateColumn Header="Gerente">
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=IsGerent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></CheckBox>
The end result is a column of your datagrid with checkbox with the common behavior of a checkbox, that with just a single click the item is checked or unchecked.
If you want all the code and the project of this example you can download it at the link below:
For questions, comments, compliments or curiosities leave a comment!
See you soon.
Um grande abraço e até a próxima!
TapiocaCom Team.

1 comment:

Tony Romo said...

Every weekend i used to pay a quick visit this web site, because i want enjoyment, for the reason that this this web page conations truly fastidious informative material too.

The Medical Websites 4 Physicians in USA.

Post a Comment