Hi, All,
I have a window form with several textboxes and these textboxes bind to a Winodw.Form.BindingSource, for example, bsActivity. Also, the bsActivity.DataSource is set to a root object m_activity. I have two read-only textboxes called modified user and modified date. When the object is updated, it is saved into the databse and these two fields is updated too. After it calls Save( ) and sets the BindingSource.DataSource to new modified object, (here, the m_activity has the new modified user and date info) but why the UI won't refresh with new info for modified user and date? I even try bs.Activity.ResetBindings(false), but it won't work either. When I close the form and re-open it, I can see the modified user and date. What should I do if I want to refresh the UI when dataSource is modified?
Thanks for your help and have a good weekend.
here is the code snippet.
this.bsActivity.RaiseListChangedEvents = false;Andy,
Thank you, I do turn on RaiseListChangedEvents, it is on finally { } parte of Try /Catch but it is not shown at the code snippet. Sorry about that.
I use your way, bsActivity.DataSource = null; bsActivity.DataSource = m_activity; but the two textboxes still don't refresh after saving the object.
Best regards,
Hi, Andres,
Here is the update method. After saved the object, I use the output parameter to get the modified date value and modified user is from Csla.ApplicationContext.User.Identity.Name.
I' m sure that I get the modified date and user in new BS, but just can not refersh window UI.
Thanks and have a good weekend.
[Csla.Transactional(Csla.TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
using (SqlConnection cn = new SqlConnection(Database.ShowSupportConnection))
using (SqlCommand cm = cn.CreateCommand())
{
cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "usp_UpdateActivity";
cm.Parameters.AddWithValue("@id", this._id);
cm.Parameters.AddWithValue("@segment_id", this._segmentId);
cm.Parameters.AddWithValue("@code", this._code);
cm.Parameters.AddWithValue("@description", this._description);
cm.Parameters.AddWithValue("@notes", this._notes);
cm.Parameters.AddWithValue("@user_name", Csla.ApplicationContext.User.Identity.Name)
cm.Parameters.AddWithValue("@change_stamp", this._changeStamp);
SqlParameter par = new SqlParameter("@newChange_Stamp", SqlDbType.Timestamp);
par.Direction = ParameterDirection.Output;
cm.Parameters.Add(par);
SqlParameter par1 = new SqlParameter("@Newmodified_date", SqlDbType.DateTime);
par1.Direction = ParameterDirection.Output;
cm.Parameters.Add(par1);
cm.ExecuteNonQuery();
_changeStamp = (byte[])cm.Parameters["@Newchange_stamp"].Value;
this._modifiedDate.Text = cm.Parameters["@Newmodified_date"].Value.ToString();
this._modifiedUser = Csla.ApplicationContext.User.Identity.Name;
}//if(base.IsDirty)
UpdateChildren(cn);
}//using
}
ajj3085:I don't turn them off (the OP was doing that).
I sorta found the problem; no PropertyHasChanged method being called (duh).
What's odd though is that the controls bound to a SmartDate property aren't refreshing, although the string properties are. Need to look into that more, I'll post back when I figure out whats wrong.
Andy
Thanks for everyone's help.
The way Tmso said works for me.( RaiseListChangedEvents has been turned back on prior to your call to ResetBindings).
Thank you all.
here is snippet code:
this.bsActivity.RaiseListChangedEvents = false;
this.bsActivity.EndEdit();
activity temp = this.m_activity.Clone();
temp.ApplyEdit();
try
{
m_activity = temp.Save();
}
catch (.... )
{
.......
}
finally
{
bsCategory.RaiseListChangedEvents = true;
m_activity.BeginEdit();
this.bsActivity.DataSource = m_activity;
}
What I have done in the past is to create a DataBind method and a DataUnBind method. After a save I call DataUnBind and then DataBind.
David
Copyright (c) Marimer LLC