Data change tracking like in DataGridView CurrentCellDirtyStateChanged?

Jun 19, 2009 at 10:24 AM

My scenario:

I'm use MVVM pattern. I'm have DataGridCheckBoxColumn. I need that at least one cell must be checked. My column:

 

<wpftk:DataGridCheckBoxColumn Header="Some text"
Binding="{Binding Path=IsDefault, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="False"
CellStyle="{StaticResource SingleClickEditing}"
Width="Auto"/>

My ViewModel need to know when Cell is checked or unchecked immideately, when user click on it. Not then focus leave cell or rise CellEndEdit event. In WinForms I can listen CurrentCellDirtyStateChanged

event and do my work, but here I'm not found any way to do that. UpdateSourceTrigger=PropertyChanged don't work. Any ideas for this?

 

Jun 20, 2009 at 11:53 AM

Well. I think this is a bug or somethig... Because when I'm replace DataGridCheckBoxColumn with DataGridTemplateColumn with CheckBox, UpdateSourceTrigger start work properly:

 

<wpftk:DataGridTemplateColumn Header="Some text"
IsReadOnly="False"
CellStyle="{StaticResource SingleClickEditing}"
Width="Auto">
    <wpftk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Path=IsDefault, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
        </DataTemplate>
    </wpftk:DataGridTemplateColumn.CellTemplate>
</wpftk:DataGridTemplateColumn>

Now, my IsDefault property receive new values when IsChecked property is changed.

 

Coordinator
Jun 23, 2009 at 4:16 AM

This is by design.  With DataGridTemplateColumn, you manage the data bindings yourself whereas the other stock columns will manage the data binding updates for you.  This is so the transaction scenario works when editing cells and rows.  Notice with DataGridTemplateColumn you don't get cell cancel functionality right out of the box.