XMLNode.ValidationError 事件
当在 XMLNode 控件中存在验证错误时发生。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)
语法
声明
Event ValidationError As EventHandler
event EventHandler ValidationError
示例
下面的代码示例使用 SetValidationError 方法为 XMLNode 设置自定义验证错误信息。 ValidationError 事件的事件处理程序会在 XMLNode 未验证时显示该自定义验证错误信息。 此示例假定当前文档包含名为 CustomerAddress1Node 和 CustomerZipNode 的两个 XMLNode 对象,这两个对象映射到整数数据类型的架构元素。
Private Sub XMLNodeValidationError()
' Set custom error message for Address1 element.
Dim errorText As String = Me.CustomerAddress1Node.BaseName & _
" element must be an integer."
Dim objErrorText As Object = CType(errorText, Object)
Me.CustomerAddress1Node.SetValidationError( _
Word.WdXMLValidationStatus.wdXMLValidationStatusCustom, _
objErrorText, False)
' This does not raise a validation error.
Dim val As Integer = 22222
Me.CustomerZipNode.NodeText = val.ToString()
' This raises a validation error.
Me.CustomerAddress1Node.NodeText = "Seventeen Hundred Twenty One"
End Sub
Private Sub CustomerNode_ValidationError(ByVal sender As Object, _
ByVal e As EventArgs) Handles CustomerZipNode.ValidationError, _
CustomerAddress1Node.ValidationError
Dim tempNode As Microsoft.Office.Tools.Word.XMLNode = CType(sender, _
Microsoft.Office.Tools.Word.XMLNode)
MsgBox("Error: " & tempNode.ValidationErrorText(False))
End Sub
private void XMLNodeValidationError()
{
// Set custom error message for Address1 element.
string errorText = this.CustomerAddress1Node.BaseName +
" element must be an integer.";
object objErrorText = (object)errorText;
this.CustomerAddress1Node.SetValidationError(
Word.WdXMLValidationStatus.wdXMLValidationStatusCustom,
ref objErrorText, false);
// Attach validation event handlers.
this.CustomerZipNode.ValidationError +=
new EventHandler(CustomerNode_ValidationError);
this.CustomerAddress1Node.ValidationError +=
new EventHandler(CustomerNode_ValidationError);
// This does not raise a validation error.
int val = 22222;
this.CustomerZipNode.NodeText = val.ToString();
// This raises a validation error.
this.CustomerAddress1Node.NodeText =
"Seventeen Hundred Twenty One";
}
void CustomerNode_ValidationError(object sender, EventArgs e)
{
Microsoft.Office.Tools.Word.XMLNode tempNode =
(Microsoft.Office.Tools.Word.XMLNode)sender;
MessageBox.Show("Error: " + tempNode.ValidationErrorText[false]);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。