Hi @Sushil Agarwal , Welcome to Microsoft Q&A,
When working with data bindings in Windows Forms, particularly with a DateTimePicker control bound to a data source, it is important to understand how the data binding mechanism works and why certain values might not automatically update in the data source.
In your scenario, it seems that the DateTimePicker control dtpSupplierbill_dt is bound to a BindingSource (bs), which in turn is connected to the grntable. The issue is that theValueproperty of theDateTimePickerdoes not update thegrn table unless you manually set the value using rowView["supp_docdt] = dtpDoc_dt.Value.Date
;.
Make sure the DataSourceUpdateMode of the Binding object is set to OnPropertyChanged.
dtpSupplierbill_dt.DataBindings.Add("Value", bs, "supp_docdt", true, DataSourceUpdateMode.OnPropertyChanged);
Before calling EndEdit
, make sure the BindingSource
is in the correct state. If the BindingSource
is not initialized correctly or if EndEdit
is called too early, changes may not be committed.
If necessary, you can force the BindingSource
to recognize the change:
bs.EndEdit();
DataRowView rowView = (DataRowView)bs.Current;
rowView.BeginEdit();
rowView["supp_docdt"] = dtpSupplierbill_dt.Value.Date;
rowView.EndEdit();
Add event handlers to the BindingSource
and DateTimePicker
to monitor changes and ensure they propagate correctly:
dtpSupplierbill_dt.ValueChanged += (s, e) => { Console.WriteLine($"DateTimePicker ValueChanged: {dtpSupplierbill_dt.Value}"); };
bs.CurrentItemChanged += (s, e) => { Console.WriteLine($"BindingSource CurrentItemChanged: {((DataRowView)bs.Current)["supp_docdt"]}"); };
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.