[英]Programmatically set fields in InfoPath form when signature is removed
我有一个InfoPath表单,上面有多个签名。 删除签名后,如何有效且以编程方式设置表单某些字段的值?
我有一个在删除签名时触发的代码块,并且已经在其他地方成功设置了字段的值,但两者似乎一起导致了此错误:
Operation is not valid, because of the current state of the object.
at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromMsxmlInteropError(MsxmlInteropError eError)
at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromHresult(Int32 hrError)
at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlNodeImpl.set_Text(String strText)
at Microsoft.Office.InfoPath.MsxmlNavigator.SetValue(String value)
at MyForm.FormCode.SetFieldValue(String xPath, String xValue, Boolean isNil)
在我看来,这似乎毫无帮助。
我正在使用的快捷键功能( SetFieldValue
和GetFieldValue
)来自此处 ,到目前为止,它们看起来很漂亮,直到我将它们放入签名更改的触发器中为止,该触发器如下所示:
public void InternalStartup()
{
// some other stuff happens in here too
EventManager.XmlEvents["/my:myFields/my:signatures1"].Changed += new XmlChangedEventHandler(signatures1_Changed);
}
public void signatures1_Changed(object sender, XmlEventArgs e)
{
XmlOperation op = e.Operation;
// Triggered only when a signature is removed
if (op == XmlOperation.Delete)
{
// If the removed signature is the specific one I'm looking for
if (e.OldParent.Name.Equals("my:signatures2"))
{
// SetFieldValue(string xPath, string newValue, bool isNil (only true if the field is of type Date))
SetFieldValue("my:super/my:long/my:form/my:xpath/my:MyField", "Hello World", false);
}
}
}
其中,触发功能已由InfoPath自动生成。
我相信发生这种情况是因为用户删除签名的唯一方法是通过内置于InfoPath的“数字签名”对话框,并且在“签名更改触发器”时,该对话框仍处于打开状态并且是模态的,因此父InfoPath窗口无法聚焦,因此无法设置该字段。 如果我只是简单地放一个MessageBox.Show("Signature Removed");
在同一位置,删除签名后,该对话框将在打开的“数字签名”对话框上方弹出。
现在,我正在研究以某种方式在尝试设置值之前以编程方式关闭“数字签名”对话框的可能性,或者甚至制作一个“ X”按钮来为用户删除签名而不必使用“数字签名”对话框,但是即使这样也不会阻止用户使用对话框,因此不能完全解决问题,这令我满意。
我要做的就是在删除签名后设置一些字段,因为InfoPath本身没有这种触发器,因此任何实现此目的的解决方案都是可以接受的。
尝试,
public string getNodeValue(string path)
{
XPathNavigator root;
string temp;
root = this.MainDataSource.CreateNavigator();
temp = root.SelectSingleNode(path, this.NamespaceManager).Value;
return temp;
}
// Set the value
public void setNodeValue(string path, string value)
{
XPathNavigator root, infopathNode;
root = this.MainDataSource.CreateNavigator();
infopathNode = null;
infopathNode = root.SelectSingleNode(path, this.NamespaceManager);
infopathNode.SetValue(value);
}
其中path是节点的xpath。 看起来像“ / my:myFields / my:theValue”,其中value是您要填充的值
我们可以从“我的设置”页面更改我的签名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.