How to programmatically reset/clear a drop-down list box - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to programmatically reset/clear a drop-down list box

Last post 11-22-2011 05:21 AM by Jimmy. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 07-12-2011 11:03 AM

    How to programmatically reset/clear a drop-down list box

     Forum Community,

     

    I'm trying to reset/clear a drop-down list box control using C#. Through some research, I was able to locate a related post (http://www.infopathdev.com/forums/t/19017.aspx), but I'm thinking there has to be a more definitive and best-practices procedure for resetting the control using C# so that it displays the default text ("Select...") .

     

    Thanks in advance for your help.

     

    ~W

  • 07-12-2011 11:14 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

    Generally, the "Select" display is if the value of the field is blank. You don't need code for this - you can use rules to set the field bound to the drop down control to blank. If you need to do it programatically, create an XPathNavigator for the node, and use SetValue to set the nav's value to blank.

    The thread you linked to seems to be about creating / clearing the options the user can select from in the dropdown. Is that what you need to instead?

    Hilary Stoupa

  • 07-12-2011 11:31 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

     Hi Hilary,

     

    No, I do not want to create/clear the options a user can select from the drop down.

     

    With regards to the suggestion in your first paragraph, how would I set the value to blank? The code I plan to use to programmatically  reset the list box control is listed below, but I don't know how to complete it:

    XPathNavigator vehicleType = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:CrewRotationPreview/my:CRD_TransportVehicleType", this.NamespaceManager);
               
    vehicleType.SetValue(<What goes here?>);

     

    Thanks,

     

    ~W

  • 07-12-2011 11:44 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

    vehicleType.SetValue("");

    Empty double quotes. Or you could use String.Empty.

    Hilary Stoupa

  • 07-12-2011 11:47 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

     Hi Hilary,

     

    It would appear the following lines of code successfully reset my drop-down list box; consequently, you may disregard my last forum post:

    XPathNavigator vehicleType = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:CrewRotationPreview/my:CRD_TransportVehicleType", this.NamespaceManager);
    vehicleType.SetValue(String.Empty);

     

    Thanks for your time :-)

     

    ~W

  • 07-12-2011 11:54 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

     Hello again,

     

    Thank you :-)

     

    ~W

  • 11-21-2011 09:42 PM In reply to

    Re: How to programmatically reset/clear a drop-down list box

    Hi,

    How can i delete the values from the list box control and show it as a blank list box control on the click of a button? Please assist!!!

     

    Thanks,

    Rosemary

  • 11-22-2011 01:53 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

    The thread that OP referred to has some pointers for accomplishing what you're describing.  You can also use qRules to do this - just use the Delete command to delete the rows that populate the listbox.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-22-2011 03:17 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

    can u please provide the piece of code to delete the rows?
  • 11-22-2011 05:21 AM In reply to

    Re: How to programmatically reset/clear a drop-down list box

    Hi RoseMary,

    Unfortunately, it's our policy not to write free code for people, because custom code in InfoPath is not a recommended practice, especially for inexperienced coders. I recommend giving qRules a try, but if you want to have a try writing your own code, I can take a look at it for you.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.