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 9126623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:04:58+00:00 2026-06-17T07:04:58+00:00

In my application, I am generating a datagrid programatically and binding it with a

  • 0

In my application, I am generating a datagrid programatically and binding it with a list. I am able to see the data in the datagrid but when I edit the cell, the underlying item in the list does not get updated. Here is the code

Window dateChangeWindow = new Window();
dateChangeWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
dateChangeWindow.Owner = Application.Current.MainWindow;
dateChangeWindow.SizeToContent = SizeToContent.WidthAndHeight;
dateChangeWindow.Title = "Date Change";

StackPanel stackPanel = new StackPanel();
stackPanel.Orientation = Orientation.Vertical;

DataGrid requestGrid = new DataGrid();
requestGrid.CanUserResizeColumns = false;
requestGrid.CanUserResizeRows = false;
requestGrid.CanUserReorderColumns = false;
requestGrid.CanUserSortColumns = true;
requestGrid.AutoGenerateColumns = false;

DataGridTextColumn requestIdColumn = new DataGridTextColumn();
requestIdColumn.Header = "Request Id";
Binding idBinding = new Binding("RequestId");
idBinding.Mode = BindingMode.OneWay;
requestIdColumn.Binding = idBinding;
requestGrid.Columns.Add(requestIdColumn);

DataGridTemplateColumn startDateColumn = new DataGridTemplateColumn();
startDateColumn.Header = "Start Date";
Binding startDateBinding = new Binding("StartDate");
startDateBinding.Mode = BindingMode.TwoWay;
FrameworkElementFactory startDateFactory = new FrameworkElementFactory(typeof(DatePicker));
startDateFactory.SetBinding(DatePicker.SelectedDateProperty, startDateBinding);
DataTemplate startDateTemplate = new DataTemplate();
startDateTemplate.VisualTree = startDateFactory;
startDateColumn.CellTemplate = startDateTemplate;
startDateColumn.CellEditingTemplate = startDateTemplate;
requestGrid.Columns.Add(startDateColumn);

DataGridTemplateColumn endDateColumn = new DataGridTemplateColumn();
endDateColumn.Header = "End Date";
Binding endDateBinding = new Binding("EndDate");
endDateBinding.Mode = BindingMode.TwoWay;
FrameworkElementFactory endDateFactory = new FrameworkElementFactory(typeof(DatePicker));
endDateFactory.SetBinding(DatePicker.SelectedDateProperty, endDateBinding);
DataTemplate endDateTemplate = new DataTemplate();
endDateTemplate.VisualTree = endDateFactory;
endDateColumn.CellTemplate = endDateTemplate;
endDateColumn.CellEditingTemplate = endDateTemplate;
requestGrid.Columns.Add(endDateColumn);

requestGrid.ItemsSource = requestList;
requestGrid.Margin = new Thickness(0, 10, 0, 0);
requestGrid.HorizontalAlignment = HorizontalAlignment.Center;

stackPanel.Children.Add(requestGrid);

Button changeDoneBtn = new Button();
changeDoneBtn.Content = "Submit";
changeDoneBtn.Click += new RoutedEventHandler(changeDone_Click);
changeDoneBtn.Margin = new Thickness(0, 20, 0, 10);
changeDoneBtn.HorizontalAlignment = HorizontalAlignment.Center;

stackPanel.Children.Add(changeDoneBtn);

dateChangeWindow.Content = stackPanel;
dateChangeWindow.ShowDialog();

The ItemsSource requestList is populated before the window creation. It is declared as

IList<DateChangeWrapper> requestList = new List<DateChangeWrapper>();

And the DateChangeWrapper class looks like this

public class DateChangeWrapper : INotifyPropertyChanged
{
    public DateChangeWrapper(ResponseWrapper responseWrapper)
    {
        RequestId = responseWrapper.RequestId;
        ParentRequestId = responseWrapper.ParentRequestId;
        StartDate = responseWrapper.StartDate;
        EndDate = responseWrapper.EndDate;
    }

    private DateTime startDate;
    private DateTime endDate;

    public int RequestId { get; private set; }
    public int ParentRequestId { get; private set; }

    public DateTime StartDate
    {
        get { return startDate; }
        set
        {
            startDate = value;
            OnPropertyChanged("StartDate");
        }
    }

    public DateTime EndDate
    {
        get { return endDate; }
        set
        {
            endDate = value;
            OnPropertyChanged("EndDate");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;  

    private void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            var e = new PropertyChangedEventArgs(propertyName);
            handler(this, e);
        }
    }
}

As you can see from the code, I have two columns StartDate and EndDate which are displayed as DatePickers . When I debug the code, the point where window.ShowDialog is called, I see the get accessor of the Dates getting called. But when I change the value in the datepicker, the setter does not get called and my list still has the old value.

Please help me

  • 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-17T07:05:00+00:00Added an answer on June 17, 2026 at 7:05 am

    The problem was that the changed value was not getting updated back to the underlying source because of UpdateSourceTrigger. By default, this has the value of LostFocus. I changed it to PropertyChanged and it worked ! 🙂

    I added the following line of code to my binding

    startDateBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    

    and similarly for EndDate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my VB application I am generating XML document based on data fetched from
In my asp.net, C# application we are generating and downloading .xls file. But when
So I am generating XML data in my RoR application for an external source
I have created a console application responsible for generating exports of data from a
Our application does some relatively complex stuff, resulting in each request generating somewhere between
I'm generating an HTML report for showing table data in a web application, using
In our intranet application we are generating and displaying word documents. Users can edit
I'm generating some XML data in a Delphi application, in response to an HTTP
I have an application and I am generating Jasper Reports from it. But when
It's a third party application generating huge amounts of log entries on our app

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.