Muhammad Nasir
Muhammad Nasir

Reputation: 2204

RowEditEnding event for DataGridTemplateColumn is not working

I have following wpf grid i want to call RowEditEnding event when user change event is not working for DataGridTemplateColumn . DataGridTemplateColumn excute only when i change values in datagrid defined controls like DataGridTextColumn,DataGridComboBoxColumn,etc

   <DataGrid Name="DriversDataGrid" Width="360" ItemsSource="{Binding GetAll}" CommandManager.PreviewExecuted="DriversDataGrid_PreviewDeleteCommandHandler" AutoGenerateColumns="False" RowEditEnding="DataGrid_RowEditEnding">
      <DataGrid.Columns>
         <DataGridTemplateColumn Header="Latest Victory Date" >
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                <DatePicker SelectedDate="{Binding LatestVictory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0></DatePicker>
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
         </DataGridTemplateColumn >
     </DataGrid.Columns>
  </DataGrid>

here is my event code

  private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {

                FormulaOneDriver driver = e.Row.DataContext as FormulaOneDriver;
                MessageBox.Show("test");
                driver.Save();

            }
        }

How to call RowEditEnding event for data in change in DataGridTemplateColumn elements.

Upvotes: 0

Views: 1885

Answers (1)

The Mean Fiddler
The Mean Fiddler

Reputation: 21

Add a CellEditingTemplate. This requires the user to click twice - once to select the cell and again to go into CellEditing mode

            <DataGridTemplateColumn Header="Latest Victory Date" SortMemberPath="LatestVictory">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding LatestVictory, Mode=TwoWay}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <DatePicker SelectedDate="{Binding LatestVictory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ConverterCulture='en-GB', StringFormat=d}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>

Upvotes: 1

Related Questions