Datagrid Datepicker cant cancel out changes with escape key

May 28, 2009 at 5:10 PM

I am using a Datepicker in my datagrid as shown below

                     <my:DataGridTemplateColumn Header="expiryDate" Width="*">
                        <my:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <my:DatePicker SelectedDate="{Binding Path=expiryDate}" SelectedDateFormat="Short" />
                            </DataTemplate>
                        </my:DataGridTemplateColumn.CellEditingTemplate>
                        <my:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Path=expiryDate, StringFormat=d}" />
                            </DataTemplate>
                        </my:DataGridTemplateColumn.CellTemplate>
                    </my:DataGridTemplateColumn>

This is working fine.

The issue I am having is that if the user changes the date then changes his mind and wants to cancel out by hitting the ESCAPE key (tried multiple escape as well), it does not revert back to the original value.

Is there some other way to get this working?

 

Coordinator
May 30, 2009 at 2:31 PM
Edited May 30, 2009 at 2:31 PM

You need to update the binding in CellEditingTemplate to:

Binding Path=expiryDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

and your data item needs to implement IEditableObject.  Even with that though, you'll see need to press esc twice for the item to revert.  This is a limitation of bindings in DataGridTemplateColumn.

Jun 1, 2009 at 5:51 PM

Thank you!

I was able to implement IEditableObject and with the binding changes you specified, I am now able to cancel the date changes.

 

Jun 4, 2009 at 1:19 AM

In trying to pass this dataset through a WCF service, I run into the same issue since the data class with IEditableObject definition is on the service side.

Thus the Begin/Ending events are not generated/captured.

Is there a way of overcoming this issue?