Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting changes in children
Message
 
To
15/10/2004 12:34:07
Max Fillmore
Essential Skills, Inc.
Lenexa, Kansas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00951764
Message ID:
00952383
Views:
15
Max,

>I have a form based on mmBusinessForm with child business objects which are editted in grid controls. I also have the navigation connected to the main form toolbar.
>
>If the user makes changes to either the primary bizobj or any of the children and then presses one of the navigation buttons there is no prompt to save changes. This causes the loss of all edits in the child rows as the child datasets are repopulated when the the primary bizobj advances to the next row.
>
>How do I make form navigation detect changes in the child business objects?

We've added logic to MM .NET for the next version so it does this automatically, but for now, if you want to get it to work in your application's forms, you need to override the form's NavigateData() method as follows:
public override void NavigateData(mmNavigate navPosition, bool raiseEvents)
{
	if (this.ActiveControl != null)
	{
		// Make sure the current UI control value is written back to the data
		mmDataGrid grid = this.ActiveControl.Parent as mmDataGrid;
		if (grid != null)
		{
			grid.EndEdit(null, grid.CurrentRowIndex, false);

			DataSet ds = grid.DataSource as DataSet;
			if (ds != null)
			{
				// Determine the table name
				string TableName = null, ViewName = null;

				mmBusinessObject BizObj = 
					(mmBusinessObject)mmAppDesktop.FormMgr.GetControlBizObj(grid);
				if (BizObj != null)
				{
					mmBindingStrategyBase.GetBindingSource(BizObj,
						grid.BindingSourceMember,
						out TableName,
						out ViewName);
				}
				if (!mmString.Empty(TableName))
				{
					ds.Tables[TableName].Rows[grid.CurrentRowIndex].EndEdit();
				}
				else
				{
					ds.Tables[0].Rows[grid.CurrentRowIndex].EndEdit();
				}
			}
			else
			{
				DataView dv = grid.DataSource as DataView;
				if (dv != null)
				{
					dv.Table.Rows[grid.CurrentRowIndex].EndEdit();
				}
			}
		}
		else
		{
			Control cntrl = this.ActiveControl as Control;
			if (cntrl != null && cntrl.DataBindings.Count > 0)
			{
				this.BindingContext[cntrl.DataBindings[0].DataSource].EndCurrentEdit();
			}
		}
	}

	// Check for changes
	if (this.IsChanged())
	{
		Control CancelControl = this.FocusOnCancelControl;
		Control SaveControl = this.FocusOnSaveControl;
		this.FocusOnCancelControl = null;
		this.FocusOnSaveControl = null;
				
		// Ask the user if they want to save changes
		DialogResult result = this.AskSaveChanges();

		this.FocusOnCancelControl = CancelControl;
		this.FocusOnSaveControl = SaveControl;

		if (result == DialogResult.Cancel)
		{
			return;
		}
	}
	base.NavigateData (navPosition, raiseEvents);
}
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform