<?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>General</title><link>https://www.infopathdev.com:443/forums/41.aspx</link><description>If you're not sure where to ask your question, ask it here. If necessary, our moderators will make sure it gets classified in the correct board.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Secondary DataSource/Repeating Table population</title><link>https://www.infopathdev.com:443/forums/thread/98844.aspx</link><pubDate>Wed, 27 Aug 2014 18:55:24 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:98844</guid><dc:creator>Hilary Stoupa</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/98844.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=98844</wfw:commentRss><description>&lt;p&gt;I find getting code to format nicely on the forum a real challenge. I usually use the indent button to give me a block quote and then (please don&amp;#39;t laugh) paste my code from Visual Studio into a rich text box in InfoPath and then from there into Word and then into my forum post. Ridiculous, right? I think attaching a text file is a much better work around.&lt;/p&gt;</description></item><item><title>Re: Secondary DataSource/Repeating Table population</title><link>https://www.infopathdev.com:443/forums/thread/98827.aspx</link><pubDate>Wed, 27 Aug 2014 13:57:00 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:98827</guid><dc:creator>arkainus</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/98827.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=98827</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/infopathdev/images/icon-quote.gif"&gt; &lt;strong&gt;arkainus:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
--snip--&lt;/div&gt;&lt;/BLOCKQUOTE&gt;

I figured it out. I ended up using a StringBuilder object, and performing a foreach loop on my XPathNodeIterator, because for whatever reason rows.MoveNext() never seemed to advance to the next row for me. I&amp;#39;m sure I screwed up somewhere in there, but I wasn&amp;#39;t finding it. I built the repeating table using the StringBuilder object so I only had to call AppendChild() for the repeating table once, which cut down on the CPU cost of the function. If anyone ever runs across this, I would still love a guide on how to properly format posts that contain code, etc.  Anyhow, thank you for being a great resource for infopath developers to tap into.</description></item><item><title>Re: Secondary DataSource/Repeating Table population</title><link>https://www.infopathdev.com:443/forums/thread/98816.aspx</link><pubDate>Mon, 25 Aug 2014 21:30:14 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:98816</guid><dc:creator>arkainus</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/98816.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=98816</wfw:commentRss><description>Sorry, my post was truncated, or something? If I edit it, it all is there in the editor, but when posted, it looks truncated. I have attached a text file that has the post, formatting and all to my original post. 

Is there a guide to show how best to make posts here that contain code? I&amp;#39;m assuming that is the issue...</description></item><item><title>Secondary DataSource/Repeating Table population</title><link>https://www.infopathdev.com:443/forums/thread/98814.aspx</link><pubDate>Mon, 25 Aug 2014 21:24:59 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:98814</guid><dc:creator>arkainus</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/98814.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=98814</wfw:commentRss><description>Hi,

I&amp;#39;m not 100% sure where this should be filed, but I&amp;#39;m hoping someone can help me out here.  I have a secondary Datasource, which performs a lookup to a sharepoint list to pull down info. This datasource is used to populate a dropdown box for a list. What I was attempting to do, was after the user selects a value for the dropdown box, use that to populate a repeating table with all entries that are valid for that entity. I created a changed event in my code and did the following (which is essentially similar to these -  (http://www.infopathdev.com/forums/p/9873/90584.aspx and http://www.bizsupportonline.net/infopath2007/copy-rows-from-sharepoint-list-to-main-data-source.htm)
&lt;br /&gt;&lt;br /&gt;
my code looks like the following:
&lt;br /&gt;&lt;br /&gt;
&lt;code&gt;namespace NewMatterRequest&lt;br /&gt;
{&lt;br /&gt;
    public partial class FormCode &lt;br /&gt;
    {&lt;br /&gt;
        // Member variables are not supported in browser-enabled forms.&lt;br /&gt;
        // Instead, write and read these values from the FormState &lt;br /&gt;
        // dictionary using code such as the following:&lt;br /&gt;
        //&lt;br /&gt;
        // private object _memberVariable&lt;br /&gt;
        // {&lt;br /&gt;
        //     get&lt;br /&gt;
        //     {&lt;br /&gt;
        //         return FormState[&amp;quot;_memberVariable&amp;quot;];&lt;br /&gt;
        //     }&lt;br /&gt;
        //     set&lt;br /&gt;
        //     {&lt;br /&gt;
        //         FormState[&amp;quot;_memberVariable&amp;quot;] = value;&lt;br /&gt;
        //     }&lt;br /&gt;
        // }&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
        // NOTE: The following procedure is required by Microsoft InfoPath.&lt;br /&gt;
        // It can be modified using Microsoft InfoPath.&lt;br /&gt;
&lt;br /&gt;
        private void DeleteFirstEmptyItem()&lt;br /&gt;
        {&lt;br /&gt;
            XPathNavigator domNav = MainDataSource.CreateNavigator();&lt;br /&gt;
            XPathNavigator itemNav = domNav.SelectSingleNode(&lt;br /&gt;
            &amp;quot;/my:myFields/my:group1/my:group2[1]&amp;quot;,&lt;br /&gt;
            NamespaceManager);&lt;br /&gt;
&lt;br /&gt;
            if (itemNav != null)&lt;br /&gt;
                itemNav.DeleteSelf();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static string GetValueOrEmptyString(XPathNavigator node)&lt;br /&gt;
        {&lt;br /&gt;
            return node == null ? string.Empty : node.Value;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        private void AddItem(string suretyname, string clientno, string status, string relationship)&lt;br /&gt;
        {&lt;br /&gt;
            XPathNavigator mainDS = MainDataSource.CreateNavigator();&lt;br /&gt;
            XPathNavigator group1 = mainDS.SelectSingleNode(&lt;br /&gt;
                &amp;quot;/my:myFields/my:group1&amp;quot;, NamespaceManager);&lt;br /&gt;
&lt;br /&gt;
            group1.AppendChildElement(&amp;quot;my&amp;quot;, &amp;quot;group2&amp;quot;, NamespaceManager.LookupNamespace(&amp;quot;my&amp;quot;), &amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
            XPathNodeIterator iter = mainDS.Select(&amp;quot;/my:myFields/my:group1/my:group2&amp;quot;, NamespaceManager);&lt;br /&gt;
&lt;br /&gt;
            int rowCount = 0;&lt;br /&gt;
            if (iter != null)&lt;br /&gt;
                rowCount = iter.Count;&lt;br /&gt;
&lt;br /&gt;
            XPathNavigator lastGroup2 = mainDS.SelectSingleNode(&lt;br /&gt;
                &amp;quot;/my:myFields/my:group1/my:group2[&amp;quot; + rowCount + &amp;quot;]&amp;quot;, NamespaceManager);&lt;br /&gt;
&lt;br /&gt;
            if (lastGroup2 != null)&lt;br /&gt;
            {&lt;br /&gt;
                lastGroup2.AppendChildElement(&amp;quot;my&amp;quot;, &amp;quot;field1&amp;quot;, NamespaceManager.LookupNamespace(&amp;quot;my&amp;quot;), suretyname);&lt;br /&gt;
                lastGroup2.AppendChildElement(&amp;quot;my&amp;quot;, &amp;quot;field2&amp;quot;, NamespaceManager.LookupNamespace(&amp;quot;my&amp;quot;), clientno);&lt;br /&gt;
                lastGroup2.AppendChildElement(&amp;quot;my&amp;quot;, &amp;quot;field3&amp;quot;, NamespaceManager.LookupNamespace(&amp;quot;my&amp;quot;), status);&lt;br /&gt;
                lastGroup2.AppendChildElement(&amp;quot;my&amp;quot;, &amp;quot;field4&amp;quot;, NamespaceManager.LookupNamespace(&amp;quot;my&amp;quot;), relationship);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public void InternalStartup()&lt;br /&gt;
        {&lt;br /&gt;
            EventManager.XmlEvents[&amp;quot;/my:myFields/my:fielddb&amp;quot;].Changed += new XmlChangedEventHandler(field4_Changed);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public void field4_Changed(object sender, XmlEventArgs e)&lt;br /&gt;
        {&lt;br /&gt;
            // Write your code here to change the main data source.&lt;br /&gt;
&lt;br /&gt;
            //retrieve value of dropdown box for comparison purposes&lt;br /&gt;
            string value = MainDataSource.CreateNavigator().SelectSingleNode(&lt;br /&gt;
                &amp;quot;/my:myFields/my:fielddb&amp;quot;, NamespaceManager).Value;&lt;br /&gt;
&lt;br /&gt;
            XPathNavigator secDSNav = DataSources[&amp;quot;Surety&amp;quot;].CreateNavigator();            &lt;br /&gt;
&lt;br /&gt;
            // Retrieve the rows of the secondary data source&lt;br /&gt;
            XPathNodeIterator rows = secDSNav.Select(&lt;br /&gt;
            &amp;quot;/dfs:myFields/dfs:dataFields/ns1:SharePointListItem_RW&amp;quot;, NamespaceManager);&lt;br /&gt;
&lt;br /&gt;
            // Loop through the rows of the secondary data source and fill the repeating table&lt;br /&gt;
            while (rows.MoveNext())&lt;br /&gt;
            {&lt;br /&gt;
                string suretyname = GetValueOrEmptyString(rows.Current.SelectSingleNode(&lt;br /&gt;
                &amp;quot;/dfs:myFields/dfs:dataFields/ns1:SharePointListItem_RW/ns1:Surety_x0020_Insurer_x0020_Name&amp;quot;, NamespaceManager));&lt;br /&gt;
&lt;br /&gt;
                if (suretyname == value)&lt;br /&gt;
                {&lt;br /&gt;
                    string clientno = GetValueOrEmptyString(rows.Current.SelectSingleNode(&lt;br /&gt;
                        &amp;quot;/dfs:myFields/dfs:dataFields/ns1:SharePointListItem_RW/ns1:Title&amp;quot;, NamespaceManager));&lt;br /&gt;
                    string status = GetValueOrEmptyString(rows.Current.SelectSingleNode(&lt;br /&gt;
                        &amp;quot;/dfs:myFields/dfs:dataFields/ns1:SharePointListItem_RW/ns1:Matter_x0020_Open_x0020_or_x0020&amp;quot;, NamespaceManager));&lt;br /&gt;
                    string relationship = GetValueOrEmptyString(rows.Current.SelectSingleNode(&lt;br /&gt;
                        &amp;quot;/dfs:myFields/dfs:dataFields/ns1:SharePointListItem_RW/ns1:Adverse_x002f_Represent&amp;quot;, NamespaceManager));&lt;br /&gt;
&lt;br /&gt;
                    // Add the item to the repeating table&lt;br /&gt;
                    AddItem(suretyname, clientno, status, relationship);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;

            // Remove the first empty item from the repeating table&lt;br /&gt;
            DeleteFirstEmptyItem();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
When I run this, I have two issues: 1). It only works if I select the first item in the dropdown box and 2). When it works using the first value of the dropdown box, instead of only performing the AddItem() on the items that have the same name as that value, it does it for all 400+ items in that list.  Running through debug, I see that the value called here: &amp;quot;string suretyname = GetValueOrEmptyString(rows.Current.SelectSingleNode(&lt;br /&gt;
                &amp;quot;/dfs:myFields/dfs:dataFields/ns1:SharePointListItem_RW/ns1:Surety_x0020_Insurer_x0020_Name&amp;quot;, NamespaceManager));&amp;quot; &lt;br /&gt;
&lt;br /&gt;
never changes throughout the life of the loop, and is never equal to any other value other than the first value of the dropdown box, so seemingly those selectsinglenode calls only ever see the first result.&lt;br /&gt;
&lt;br /&gt;
I guess my questions are:&lt;br /&gt;
&lt;br /&gt;
1. how do I make the loop iterate through each result from the rows and do this? I was under the impression that the rows.moveNext() would be essentially a for-each loop, but that doesn&amp;#39;t seem to be the case. &lt;br /&gt;
2. In a couple of the examples I linked, I note that when calling the rows.Current.SelectSingleNode() operation, the namespace is just &amp;quot;@&amp;quot;, i.e. &amp;quot;@First_Name&amp;quot; in one of them. If I try that infopath raises an exception. What does the &amp;quot;@ do in the examples posted? I used the Copy Xpath function from my secondary datasource in order to fill in the location on my rows.current.selectsinglenode() calls. &lt;br /&gt;
3. Am I doing this in a totally stupid way? Is there a way to filter this datasource programmatically? In the infopathdev forum post I linked above Hilary Stoupa suggests a method, but I can&amp;#39;t seem to get it to work. Of course, that could be all related to the issues I&amp;#39;m having already? &lt;br /&gt;
&lt;br /&gt;
Does anyone have any help or insight available into what I am doing wrong here? I&amp;#39;ve been staring at this for several hours and am not making any headway &amp;gt;.&lt;br /&gt;</description></item></channel></rss>