_XDocumentEventSink2_Event.OnLoad イベント
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
Microsoft InfoPath フォームが読み込まれた後、ビューが初期化される前に発生します。
public:
event Microsoft::Office::Interop::InfoPath::SemiTrust::_XDocumentEventSink2_OnLoadEventHandler ^ OnLoad;
event Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_OnLoadEventHandler OnLoad;
member this.OnLoad : Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_OnLoadEventHandler
Event OnLoad As _XDocumentEventSink2_OnLoadEventHandler
イベントの種類
例
次の例では、OnLoad イベント ハンドラーを使用して、フォームがデジタル署名されているかどうかを確認し、まだ署名されていない場合は、あらかじめ用意されている関数とカスタム関数を併用して日付をいくつか初期化しています。
[InfoPathEventHandler(EventType=InfoPathEventType.<span class="label">OnLoad</span>)]
public void OnLoad(DocReturnEvent e)
{
// Avoid DOM updates when the document has been digitally signed.
if (thisXDocument.IsSigned)
{
return;
}
string today = thisXDocument.Util.Date.Today().ToString();
initializeNodeValue("/sls:salesReport/sls:date", today);
}
この Onload イベント ハンドラーの例は、 と setNodeValue
の 2 つのカスタム関数initializeNodeValue
に依存します。
private void initializeNodeValue(string xpath, string strValue)
{
IXMLDOMNode xmlNode = thisXDocument.DOM.selectSingleNode(xpath);
// Set the node value *ONLY* if the node is empty.
if (xmlNode.text == "")
{
setNodeValue(xmlNode, strValue);
}
}
private void setNodeValue(IXMLDOMNode xmlNode, string strValue)
{
if (xmlNode == null)
{
return;
}
// The xsi:nil needs to be removed before we set the value.
if (strValue != "" && xmlNode.attributes.getNamedItem("xsi:nil") != null)
{
xmlNode.attributes.removeNamedItem("xsi:nil");
}
// Setting the value would mark the document as dirty.
// Let's do that if the value has really changed.
if (xmlNode.text != strValue)
{
xmlNode.text = strValue;
}
}
次の例では、OnLoad イベント ハンドラーを使用して、フォームがデジタル署名されているかどうかを確認し、まだ署名されていない場合は、あらかじめ用意されている関数とカスタム関数を併用して日付をいくつか初期化しています。
[InfoPathEventHandler(EventType=InfoPathEventType.<span class="label">OnLoad</span>)]
public void OnLoad(DocReturnEvent e)
{
// Avoid DOM updates when the document has been digitally signed.
if (thisXDocument.IsSigned)
{
return;
}
string today = thisXDocument.Util.Date.Today().ToString();
initializeNodeValue("/sls:salesReport/sls:date", today);
}
この Onload イベント ハンドラーの例は、 と setNodeValue
の 2 つのカスタム関数initializeNodeValue
に依存します。
private void initializeNodeValue(string xpath, string strValue)
{
IXMLDOMNode xmlNode = thisXDocument.DOM.selectSingleNode(xpath);
// Set the node value *ONLY* if the node is empty.
if (xmlNode.text == "")
{
setNodeValue(xmlNode, strValue);
}
}
private void setNodeValue(IXMLDOMNode xmlNode, string strValue)
{
if (xmlNode == null)
{
return;
}
// The xsi:nil needs to be removed before we set the value.
if (strValue != "" && xmlNode.attributes.getNamedItem("xsi:nil") != null)
{
xmlNode.attributes.removeNamedItem("xsi:nil");
}
// Setting the value would mark the document as dirty.
// Let's do that if the value has really changed.
if (xmlNode.text != strValue)
{
xmlNode.text = strValue;
}
}
注釈
このイベント ハンドラーでは、ユーザーが操作を取り消せます。
オブジェクトの ReturnStatus プロパティが DocReturnEventObjectfalse に設定されている場合、InfoPath はフォームの読み込みを取り消します。 OnLoad イベントに関するコードでエラーが発生した場合は、そのエラーが無視され、ReturnStatus プロパティに応じて処理が実行されます。 ReturnStatus プロパティが明示的に設定されていない場合は、既定値 true が使用されます。
注: OnLoad イベントが発生すると、ビューは初期化されず、ビューに使用される XSL 変換 (XSLT) はまだ読み込まれません。 XDocumentOnLoad イベントが発生するまで、オブジェクトはコレクションに追加XDocumentsCollectionされません。 ただし、XDocument オブジェクトは OnLoad イベントの発生中でも使用できます。
重要: このイベントには、完全信頼セキュリティ レベルが必要です。 このセキュリティ レベルを設定するには、InfoPath デザイン ウィンドウで [ツール] メニューの [フォームのオプション] をクリックし、[セキュリティ] タブの [完全信頼] をクリックします。 あらかじめ完全信頼フォームをインストールまたはデジタル署名しておく必要があります。
適用対象
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示