Microsoft Office Tutorials and References
In Depth Information
Form-level events
Here's an example of the ContextChanged event.
public void FormEvents_ContextChanged(object sender,
ContextChangedEventArgs e)
{
if (e.ChangeType == "ContextNode")
{
// Position a XPathNavigator on the DisplayContext field.
XPathNavigator rtNode, msgTxtBox;
rtNode = this.MainDataSource.CreateNavigator();
msgTxtBox = rtNode.SelectSingleNode("/my:myFields/my:field2",
this.NamespaceManager);
// Set DisplayContext with the name of the current context.
msgTxtBox.SetValue("Context Name: " + e.Context.Name + ",
Context Type: " + e.Context.NodeType);
//Even you can change the view on context change
//Switching view after the context change
ViewInfos.SwitchView("Context Changed");
return;
}
}
Using the Submit event
If your InfoPath form is also on a hosted Microsoft Office InfoPath 2007 form that
uses the Submit event handler, the Submit event always occurs first in the InfoPath
form and then in the host form.
FormEvents_Submit(object sender, SubmitEventArgs e)
If the code in the Submit event in InfoPath 2007 cancels the event due to an error,
the Submit event in the host form will not occur, and the user may receive an
error message stating that The form cannot be submitted. The following code
demonstrates the use of the Submit event.
private bool Validate()
{
string strAge = MainDataSource.CreateNavigator().
SelectSingleNode("/my:myFields/my:MyAge",
NamespaceManager).InnerXml;
if (strAge.Length == 0)
{
MessageBox.Show("Please enter your age!");
return false;
}
return true;
}
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
 
Search JabSto ::




Custom Search