cascading dropdown lists don't show output correctly - InfoPath Dev
in

InfoPath Dev

cascading dropdown lists don't show output correctly

Last post 06-08-2009 10:24 AM by dvnandover. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 06-05-2009 01:17 PM

    cascading dropdown lists don't show output correctly

    I can't figure it out, so please help:

    Database tables:
    table1 has two columns named id, location and location column will be display in dropdownlist1.
    table2 has many columns including a Resource column that i want to display in dropdownlist2 when the user select a name from dropdownlist1, content of dropdownlist2 should dipslay the right choices only. The two tables are linked by id column

    Dataconnections queries:
    1. select "ID","LOCATION" from "dbo"."ScheduleLocation" as "Location"
    2. shape
    {select "ID","Resource" from "dbo"."ScheduleResource" as "ScheduleResource"} as "ScheduleResource"
    append
    ({select "ID","LOCATION" from "dbo"."ScheduleLocation" as "ScheduleLocation"}
    relate "ID" TO "ID") as "ScheduleLocation"

    And here are my event handler:
    public void Location_Changed(object sender, XmlEventArgs e)
    {
         string dataConnectionName = "ScheduleResource";
         string dataSourceName = "ScheduleResource";
         string ForeignKey = "LOCATION";
         string cascadingDropDownDataSourceField = "/my:myFields/my:Resource";
         string selectedLocationValue = e.NewValue;
         string repeatingNode = "/dfs:myFields/dfs:dataFields/d:ScheduleResource/d:ScheduleLocation";
         PopulateCascadingDropDown(selectedLocationValue, dataConnectionName, dataSourceName, repeatingNode, ForeignKey, cascadingDropDownDataSourceField);
    }

    private void PopulateCascadingDropDown(string selectedLocationValue, string dataConnectionName, string dataSourceName, string repeatingNode,
                                                                                          string ForeignKey, string cascadingDropDownDataSourceField)
    {
         XPathNavigator xnMain = this.MainDataSource.CreateNavigator();
         xnMain.SelectSingleNode(cascadingDropDownDataSourceField,this.NamespaceManager).SetValue(string.Empty);

         DataConnection dcSecond = this.DataConnections[dataConnectionName];
         dcSecond.Execute();

         XPathNavigator xnFD =this.DataSources[dataSourceName].CreateNavigator();

         string xPathString = repeatingNode + "[@" + ForeignKey + "!='" + selectedLocationValue + "']";

         XPathNodeIterator items = xnFD.Select(xPathString,this.NamespaceManager);
         while (items.Count != 0)
         {
              xnFD.SelectSingleNode(xPathString,
              this.NamespaceManager).DeleteSelf();
              items = xnFD.Select(xPathString, this.NamespaceManager);
         }
    }

    The problem was, dropdownlist2 always display the entire content regardless what selected in dropdownlist1. Can someone help pointing out the issue? did I implemented correctly? Thank you in advance.

  • 06-05-2009 10:44 PM In reply to

    Re: cascading dropdown lists don't show output correctly

    Hi -- and welcome. I'm not certain why you are doing this in code. You can use XPath to filter the second dropdown instead. Check out this Office Online tutorial for more information.

    Hilary Stoupa

  • 06-06-2009 05:31 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    Because InfoPath Form Services doesn’t allow you to use them, like you can use the with InfoPath Client according to some of the post from the users that i read from the web. And i would like to have the form launched from using web browser.

  • 06-06-2009 10:18 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    You are using Frederik's code, is that correct?

    I think that one problem you are having is that you probably have a more complex data structure than his sample does. From the looks of the SQL statement to get your Region information, I'd think you'd need to modify the following lines:

    Instead of:
    string repeatingNode = "/dfs:myFields/dfs:dataFields/d:ScheduleResource/d:ScheduleLocation";
    Use:
    string repeatingNode = "/dfs:myFields/dfs:dataFields/d:ScheduleResource[d:ScheduleLocation/";

    and

    Instead of:
    string xPathString = repeatingNode + "[@" + ForeignKey + "!='" + selectedLocationValue + "']";
    Use:
    string xPathString = repeatingNode + "@" + ForeignKey + "!='" + selectedLocationValue + "']";

    I think that what is happening is you are removing the Schedule Location nodes when you really want to be removing the Schedule Resource nodes.

    Here are two suggestions that may help you work through this issue. First, drag the ScheduleResource data source onto your form somewhere and create a section with controls. This way you can see the data you have before and after the changed event. Second, try running your code in debug -- please forgive me if I'm telling you something you already know, but assuming you are using VSTA, in the code window, where you have your code, click in the margin at the first line in the PopulateCascadingDropDown method (XPathNavigator xnMain = this.MainDataSource.CreateNavigator();). You'll see a red dot. That's a break point. Now, up in the toolbar, click the green arrow button -- looks like a 'Play' button. Your form will open in preview. Change the Location drop down value to trigger the Changed event. Now you should have focus returned to the code window, and you'll probably see the line that you marked highlighted.

    You can use Debug / Step Over (Shift + F8) to walk through the code. Hovering your mouse over initialized variables will give you more information about their current value. This will help you understand a) what the code is doing and b) what you need to change to get it to work.

    Hope this helps!


    Hilary Stoupa

  • 06-08-2009 09:05 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    Yes it is frederik's codes. I modified codes as suggested by you then the event execution failed. As i step through the codes in debug mode i got the following error "'/dfs:myFields/dfs:dataFields/d:ScheduleResource[d:ScheduleLocation@LOCATION!='MGH CHELSEA']' has an invalid token" at this line of code: 'XPathNodeIterator items = xnFD.Select(xPathString,this.NamespaceManager); The xml file created by the dataSource has something like shown below.

    <dfs:myFields xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\">

    <dfs:dataFields>

    <d:ScheduleResource xmlns:d=\"http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\" LocationID=\"1\" Resource=\"20PR \" RowVersion=\"000000000105b37b\">

    <d:ScheduleLocation LocationID=\"1\" LOCATION=\"MGH\"/>

    ---

    </d:ScheduleResource>

    </dfs:dataFields>

    </dfs:myFields>

     

  • 06-08-2009 09:27 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    You need a forward slash either at the end of

     "/dfs:myFields/dfs:dataFields/d:ScheduleResource[d:ScheduleLocation";

    or at the beginning of

    "@"

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-08-2009 09:50 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    Here is the expression string:

    '/dfs:myFields/dfs:dataFields/d:ScheduleResource[d:ScheduleLocation@LOCATION!='CHELSEA']'

    where do you suggest the forward slash go?

  • 06-08-2009 10:13 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    Between ScheduleLocation and @.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-08-2009 10:24 AM In reply to

    Re: cascading dropdown lists don't show output correctly

    It worked. thank you very much for your help.

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.