<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: OnContextChange 'Non-Attribute' Error</title><link>https://www.infopathdev.com:443/forums/thread/18890.aspx</link><pubDate>Fri, 15 Sep 2006 18:11:35 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:18890</guid><dc:creator>Greg Collins</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/18890.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=18890</wfw:commentRss><description>The trick, as described above, for your scenari is to use a single field (the root node) to store the active field information.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (eventObj.Type != "ContextNode" || eventObj.IsUndoRedo)&lt;br /&gt;    return;&lt;br /&gt; &lt;br /&gt;var oRoot = XDocument.DOM.selectSingleNode("/my:myFields"); // or whatever your root node is.&lt;br /&gt;XDocument.SetNamedNodeProperty(oRoot, "ActiveField", eventObj.Context.nodeName);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then in your conditional formatting, check:&lt;br /&gt;&lt;br /&gt;xdXDocument:GetNamedNodeProperty(/, "ActiveField", "") = "my:FieldName"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;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.</description></item><item><title>Re: OnContextChange 'Non-Attribute' Error</title><link>https://www.infopathdev.com:443/forums/thread/18889.aspx</link><pubDate>Tue, 12 Sep 2006 20:23:43 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:18889</guid><dc:creator>BHar</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/18889.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=18889</wfw:commentRss><description>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.</description></item><item><title>Re: OnContextChange 'Non-Attribute' Error</title><link>https://www.infopathdev.com:443/forums/thread/18888.aspx</link><pubDate>Wed, 30 Aug 2006 20:42:51 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:18888</guid><dc:creator>Greg Collins</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/18888.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=18888</wfw:commentRss><description>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.&lt;br /&gt;&lt;br /&gt;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).&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;In your conditional formatting, instead of checking for "1", check something like this:&lt;br /&gt;&lt;br /&gt;xdXDocument:GetNamedNodeProperty(my:RootNode, "fieldname", "") = "keyword"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That should do the trick.</description></item><item><title>OnContextChange 'Non-Attribute' Error</title><link>https://www.infopathdev.com:443/forums/thread/18818.aspx</link><pubDate>Sat, 26 Aug 2006 14:36:26 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:18818</guid><dc:creator>mike@hw410s.com</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/18818.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=18818</wfw:commentRss><description>Greg&lt;br /&gt;&lt;br /&gt;I am trying to implement your '&lt;a href='http://www.infopathdev.com/howto/tutorials/default.aspx?i=554349415b544aa18f2dff9a864bc9af' target='_blank' title='http://www.infopathdev.com/howto/tutorials/default.aspx?i=554349415b544aa18f2dff9a864bc9af'&gt;Highlight the Active Field&lt;/a&gt;' 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).&lt;br /&gt;&lt;br /&gt;Here's the code and the associated error:&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;----------------------------&lt;br /&gt;&amp;lt;InfoPathEventHandler(EventType:=InfoPathEventType.OnContextChange)&amp;gt; _&lt;br /&gt;		Public Sub OnContextChange(ByVal e As DocContextChangeEvent)&lt;br /&gt;&lt;br /&gt;            If (e.Type &amp;lt;&amp;gt; "ContextNode") Or e.IsUndoRedo Then&lt;br /&gt;                ' XML Selection or Context has changed. Write code here to respond to the changes.&lt;br /&gt;                Return&lt;br /&gt;            End If&lt;br /&gt;            Dim strNode As String = e.Context.nodeName&lt;br /&gt;            strNode = "/dfs:myFields/dfs:dataFields/d:TSRTrack/@" + strNode&lt;br /&gt;            Dim nodCurrent As IXMLDOMNode = e.XDocument.DOM.selectSingleNode(strNode)&lt;br /&gt;            Try&lt;br /&gt;                e.XDocument.SetNamedNodeProperty(nodCurrent, "active", "0")&lt;br /&gt;            Catch ex As Exception&lt;br /&gt;            End Try&lt;br /&gt;            &lt;br /&gt;            e.XDocument.SetNamedNodeProperty(nodCurrent, "active", "1")&lt;br /&gt;		End Sub&lt;br /&gt;&lt;br /&gt;---------------------------&lt;br /&gt;Error:&lt;br /&gt;&lt;br /&gt;System.Runtime.InteropServices.COMException was unhandled by user code&lt;br /&gt;  ErrorCode=-2147209216&lt;br /&gt;  Message="An invalid parameter was specified for the SetNamedNodeProperty method.&lt;br /&gt;#65279;#65279;&lt;br /&gt;The first parameter must be a non-attribute node of the main data source."&lt;br /&gt;  Source="InfoPath"&lt;br /&gt;  StackTrace:&lt;br /&gt;       at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocument2.SetNamedNodeProperty(IXMLDOMNode pxmlMainDOMNode, String bstrPropertyName, String bstrValue)&lt;br /&gt;       at Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper.SetNamedNodeProperty(IXMLDOMNode pxmlMainDOMNode, String bstrPropertyName, String bstrValue)&lt;br /&gt;       at TechServiceRequest.TechServiceRequest.OnContextChange(DocContextChangeEvent e) in C:\Documents and Settings\young_m\My Documents\SCP InfoPath Forms\TechServiceRequest\TechServiceRequest\FormCode.vb:line 126&lt;br /&gt;       at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnContextChange(DocContextChangeEvent pEvent)&lt;br /&gt;&lt;br /&gt;-----------------------------&lt;br /&gt;&lt;br /&gt;Am I hosed?&lt;br /&gt;&lt;br /&gt;TIA,&lt;br /&gt;</description></item></channel></rss>