Changing the selected item in DropDown by Code - InfoPath Dev
in

InfoPath Dev

Changing the selected item in DropDown by Code

Last post 07-15-2005 03:05 PM by Richard. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 07-13-2005 06:36 PM

    Changing the selected item in DropDown by Code

    2 questions:

    1- Is there a way to change the selected item in the DropDown by code ??
    I query the dataconnection that the dropdown is bound to via C# code,
    in addition, I want to set the selected item for this dropdown via C# code .

    2- The standard behaviour of the dropdown is to have selected on the item whose value is 0 .. What is the idea behind this ??

  • 07-13-2005 07:25 PM In reply to

    Re: Changing the selected item in DropDown by Code

    Hi Richard,

    1 - yes, just set the value of the node. You don't need code though. You can use a rule to do this or call out to xdExtension from the default value function.

    2 - just a default I think. If it wasn't the first item in the list what would it be?

    Have you seen our Smart Combo Box? Check it out:http://www.infopathdev.com/webstore/detail.aspx?itemid=14


    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 07-14-2005 01:11 PM In reply to

    Re: Changing the selected item in DropDown by Code

    Hi Patrick ,

    I must have a custom control with other requirements, but in the mean time, trying to unleash the cascade in the repeating table using xsl which works for the most part. except:

    1-I have taken the <option/> out, so the list will have no blank item.
    2- dd2 selections works correctly for the first dd1 selection
    However, with the next dd1 selection , an empty item in the dd2 list appears, i.e goes throught the following section of the template which I chose different color for:

    dd1: my:ChoiceName value=choice/@name display=choice/@name
    dd2: my:OptionName value=choice/option/@url display=choice/option/@name

    -----------------------------
    <xsl:variable name="val" select="."></xsl:variable>
    <xsl:variable name="Chn" select="../my:ChoiceName"></xsl:variable>

    <xsl:if test="not(xdXDocument:GetDOM("choices")/DropDownchoices/choice[@name = $Chn]/option[@url=$val] or $val='' )">
    <option selected="selected" style="BACKGROUND-COLOR: #ffff22">
    <xsl:attribute name="value">
    <xsl:value-of select="$val"></xsl:value-of>
    </xsl:attribute>
    <xsl:value-of select="$val/@name"></xsl:value-of>
    </option>
    </xsl:if>

  • 07-14-2005 01:36 PM In reply to

    Re: Changing the selected item in DropDown by Code

    Hi Richard,
    I'll ask Greg to respond to this. More soon,

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 07-14-2005 02:06 PM In reply to

    Re: Changing the selected item in DropDown by Code

    Richard, I don't follow exactly what you are doing. Is the cascading list in a repeating table/section?

    What do you mean when you say "the next dd1 selection"? In this the same dd list or in a different one in a separate repeating table/section row?

    Is the list populating... but also has a blank option? Or it is nothing but a blank option?

    Greg Collins [InfoPath MVP]
    InfoPath Dev
  • 07-14-2005 02:56 PM In reply to

    Re: Changing the selected item in DropDown by Code

    here is the data
    <DropDownchoices>
    <choice name="P1">
    <option name = "a" url = "1"/>
    <option name = "b" url = "2"/>
    <option name = "c" url = "3"/>
    </choice>
    <choice name="P2">
    <option name = "aa" url = "11"/>
    <option name = "bb" url = "22"/>
    <option name = "cc" url = "33"/>
    </choice>
    </DropDownChoices>


    dd1 and dd2 are in repeating table :
    For dd1 :
    name=ChoiceName entry = /DropDownchoices/choice/@name value = . dispaly = . (xsl left alone)

    For dd2
    name=OptionName , I created a dropdown with entry=/DropDownchoices/choice/option value=@url display=@name and later modified to xd:preserve and did the changes to xsl for apply template.
    I took the empty <option/> out.


    >>What do you mean when you say "the next dd1 selection"? In this the >>same dd list or in a different one in a separate repeating >>table/section row?

    in preview of the table, you see 1 row, with dd1 and dd2, if you click on dd1 and highlight it for P1 , you see dd2 populated with a, b, c and a is selected. ( I have taken out the empty option ).

    Now, you highlight P2 in dd1, and you see that dd2 has empty field selected..?? instead of picking aa.



  • 07-14-2005 03:41 PM In reply to

    Re: Changing the selected item in DropDown by Code

    taking the whole xsl:if test solves the problem... i.e all works fine.. however going back and forth in the dd1 selections, one will loose the previously highlighted selections of dd2..

    dd1 dd2
    click on P1 ---->> shows a
    ----------------------->> click on b , shows b
    click on P2 ------------>> shows aa
    ------------------------->> click on bb
    click on P1--------------->> shows a , But it will be nice to show b


  • 07-15-2005 12:02 PM In reply to

    Re: Changing the selected item in DropDown by Code

    The kind of thing you are trying to accomplish will require writing custom code to convert "b" to "bb" and back dependingon whether you select P1 or P2.

    The reason it is not working is because dd2 has, lets say, "b" selected when dd1 = P1. When you select P2 in dd1, "b" is STILL the value of dd2. But that value does not exist as an option. You will never get it to suddenly display "bb" because its value is "b". You will need to write code to make that kind of conversion to the value stored in the dd2 field.

    Does that make sense?

    Greg Collins [InfoPath MVP]
    InfoPath Dev
  • 07-15-2005 12:37 PM In reply to

    Re: Changing the selected item in DropDown by Code

    No,

    After I took the if block , now it is working per my previous post which is acceptable, while your post may suggest that it should not be working..i.e, if the dd1 selection goes from P1 to P2, the dd2 will not display aa( first item in its list) but it does ..

    unless I misunderstood you.
  • 07-15-2005 03:05 PM In reply to

    Re: Changing the selected item in DropDown by Code

    The solution of taking the xsl:if block out , creates another problem:
    where , selecting dd1, from P1 to P2, does not fire On_After_Change of the dd2 ! eventhough the display is showing that dd2 has changed.

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