OnContextChange 'Non-Attribute' Error - InfoPath Dev
in

InfoPath Dev

OnContextChange 'Non-Attribute' Error

Last post 09-15-2006 11:11 AM by Greg Collins. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 08-26-2006 07:36 AM

    OnContextChange 'Non-Attribute' Error

    Greg

    I am trying to implement your 'Highlight the Active Field' code in VB managed code. However, I think I have hit a wall in that my fields are actually 'Attributes' (created as such probably from the datasource connection to a SQL table).

    Here's the code and the associated error:

    Code:
    ----------------------------
    <InfoPathEventHandler(EventType:=InfoPathEventType.OnContextChange)> _
    Public Sub OnContextChange(ByVal e As DocContextChangeEvent)

    If (e.Type <> "ContextNode") Or e.IsUndoRedo Then
    ' XML Selection or Context has changed. Write code here to respond to the changes.
    Return
    End If
    Dim strNode As String = e.Context.nodeName
    strNode = "/dfs:myFields/dfs:dataFields/d:TSRTrack/@" + strNode
    Dim nodCurrent As IXMLDOMNode = e.XDocument.DOM.selectSingleNode(strNode)
    Try
    e.XDocument.SetNamedNodeProperty(nodCurrent, "active", "0")
    Catch ex As Exception
    End Try

    e.XDocument.SetNamedNodeProperty(nodCurrent, "active", "1")
    End Sub

    ---------------------------
    Error:

    System.Runtime.InteropServices.COMException was unhandled by user code
    ErrorCode=-2147209216
    Message="An invalid parameter was specified for the SetNamedNodeProperty method.
    #65279;#65279;
    The first parameter must be a non-attribute node of the main data source."
    Source="InfoPath"
    StackTrace:
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocument2.SetNamedNodeProperty(IXMLDOMNode pxmlMainDOMNode, String bstrPropertyName, String bstrValue)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper.SetNamedNodeProperty(IXMLDOMNode pxmlMainDOMNode, String bstrPropertyName, String bstrValue)
    at TechServiceRequest.TechServiceRequest.OnContextChange(DocContextChangeEvent e) in C:\Documents and Settings\young_m\My Documents\SCP InfoPath Forms\TechServiceRequest\TechServiceRequest\FormCode.vb:line 126
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnContextChange(DocContextChangeEvent pEvent)

    -----------------------------

    Am I hosed?

    TIA,
  • 08-30-2006 01:42 PM In reply to

    Re: OnContextChange 'Non-Attribute' Error

    No, you should be okay. The SetNamedNodeProperty requires you to use an Element instead of an attribute. You would need to alter the code a bit.

    Instead of placing the "active" property right on the node, or in your case, attribute (which isn't allowed), set a more general property on the root node (or any other node -- just be consistent).

    Then for the name of the property use "fieldname" or something like that, and for the value of the property, use a keyword or the attribute name.

    In your conditional formatting, instead of checking for "1", check something like this:

    xdXDocument:GetNamedNodeProperty(my:RootNode, "fieldname", "") = "keyword"



    That should do the trick.
  • 09-12-2006 01:23 PM In reply to

    • BHar
    • Not Ranked
    • Joined on 09-12-2006
    • Posts 1

    Re: OnContextChange 'Non-Attribute' Error

    I am having the same problem while trying to incorporate your JScript code into a form with an Access data connection. Could you provide a more detailed (JScript) example using your original How-To code with a more complex data connection? Thanks.
  • 09-15-2006 11:11 AM In reply to

    Re: OnContextChange 'Non-Attribute' Error

    The trick, as described above, for your scenari is to use a single field (the root node) to store the active field information.


    if (eventObj.Type != "ContextNode" || eventObj.IsUndoRedo)
    return;

    var oRoot = XDocument.DOM.selectSingleNode("/my:myFields"); // or whatever your root node is.
    XDocument.SetNamedNodeProperty(oRoot, "ActiveField", eventObj.Context.nodeName);


    Then in your conditional formatting, check:

    xdXDocument:GetNamedNodeProperty(/, "ActiveField", "") = "my:FieldName"


    Please note that this could cause a conflict if you have multiple fields with an identical name. You might want to use a full XPath instead of just the name, or some other kind of keyword.
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.