DataGridCheckBoxColumn immediate binding

13,726

Solution 1

You have to set the UpdateSourceTrigger property of the Binding to PropertyChanged. The default is LostFocus.

Solution 2

The solution is to NOT use the DataGridCheckBoxColumn for this. Instead use

<dg:DataGridTemplateColumn Width="20" Header="" SortMemberPath="IsSelected">
   <dg:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <CheckBox  IsChecked="{Binding Path=IsSelected}" />
       </DataTemplate>
   </dg:DataGridTemplateColumn.CellTemplate>
 </dg:DataGridTemplateColumn>

which defaults to having its UpdateSourcerigger to PropertyChanged...

DataGridCheckBoxColumn has it's UpdateSourceTrigger set to Explicit and it cannot be changed. Read more here: http://blogs.msdn.com/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx

Share:
13,726
Johan Zell
Author by

Johan Zell

Updated on June 07, 2022

Comments

  • Johan Zell
    Johan Zell almost 2 years

    I'm using the WPF Toolkit Datagrid and have one column which is a DataGridCheckBoxColumn bound to a bool property on my ViewModel.

    My problem is that I wan't the property to get it's value updated immediately when the user checks or unchecks the checkbox.

    Now you have to navigate away from the cell in order to have the property updated. It's a checkbox. It can't be in the middle of editing like a textbox can.

  • greenoldman
    greenoldman almost 14 years
    No, it does not default to it. You have to set it manually, i.e. "UpdateSourceTrigger=PropertyChanged". Otherwise you will make changes only visually (VS2010). Anyway, BIG THANK YOU for the help.
  • Will Dean
    Will Dean over 13 years
    This worked for me (WPF4) too - perhaps this was something that changed for .NET4
  • aruno
    aruno over 12 years
    note: you need to do UpdateSourceTrigger even for a textbox inside a DataGrid. probably want PropertyChanged=LostFocus in this case (even though this is the default)
  • Richard
    Richard almost 12 years
    Not for me it doesn't. (WPF4)
  • Aducci
    Aducci about 10 years
    I had to do this when using Silverlight 5