Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:47:36+00:00 2026-06-15T02:47:36+00:00

I am using WPF DataGrid’s CellEditEnding event to validate data and perform other calculations.

  • 0

I am using WPF DataGrid’s CellEditEnding event to validate data and perform other calculations. I have TextBoxes and DatePickers as DataGridTemplateColumns.

Here is how I invoking the event handler

    private void OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        if (e.EditAction == DataGridEditAction.Cancel) return;

        DataGridCellEditEndingCommandParameter p = new DataGridCellEditEndingCommandParameter();
        if (e.Column != null)
        {
            p.BindingPropertyName = e.Column.SortMemberPath;
            if (e.Column.Header != null)
                p.ColumnHeaderName = e.Column.Header.ToString();
        }

        TextBox t = e.EditingElement as TextBox;
        if (t != null) 
            p.EndingElementValue = t.Text;
        //else if (e.EditingElement as DatePicker) 

        if (e.Row != null) p.RowItem = e.Row.Item;

        p.EventArgs = e;
        p.Sender = sender as DataGrid;

        CommandParameter = p;
        ExecuteCommand();
    }

I am converting the EditingElement as TextBox to read the value entered by the user, doing the same for DatePicker though results in null when DatePicker is edited.

<DataGridTemplateColumn x:Name="fxFwd"  Header="Value Date" Width="70" SortMemberPath = "fwFwdDate" CanUsersort = "True">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path= fxFwdDate, 
            ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}, 
            StringFormat=\{0:d\}}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <DatePicker SelectedDate="{Binding Path=fxFwdDate,
                ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}, Mode=TwoWay,
                ValidatesOnExceptions=true, NotifyOnValidationError=true}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

When I inspected the EditingElement after changing the value of DatePicker, it is being received as ContentPresenter instead of DatePicker.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:47:37+00:00Added an answer on June 15, 2026 at 2:47 am

    Set x:Name on your DatePicker control –

    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <DatePicker x:Name="datePicker" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
    

    And you can fetch the DatePicker control in code-behind like this –

    ContentPresenter contentPresenter = e.EditingElement as ContentPresenter;
    DataTemplate editingTemplate = contentPresenter.ContentTemplate;
    DatePicker dp = editingTemplate.FindName("datePicker", contentPresenter)
                                as DatePicker ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF Datagrid populated with data from one SQL table using Entity
I am using a WPF DataGrid and I have the IsSelected property of the
I've got a WPF DataGrid that I have been using for some time, and
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.
I am using the WPF toolkit datagrid to display some data and want to
I'm using a the WPF datagrid from the Microsoft CodePlex project. I have a
I am using WPF datagrid. Data I am binding to the grid is not
I am using WPF toolkit Datagrid. I have a rowvalidationrule defined on this. to
I'm using the WPF toolkit datagrid. I have it set to SelectionUnit=Cell and SelectionMode=Extended
I am using WPF MVVM Pattern. I have 2 ListBoxes and a DataGrid in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.