clearing out a text box with code - InfoPath Dev
in

InfoPath Dev

clearing out a text box with code

Last post 06-29-2015 06:36 AM by SearchKnowledge. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 07-10-2009 07:36 AM

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    clearing out a text box with code

    I'm used to visual basic and not VSTA, but ive been trying to use this code to clear some text boxes when a user hits submit.

    Dim root As XPathNavigator = MainDataSource.CreateNavigator()
    Dim textbox As String = root.SelectSingleNode("my:myFields/my:textbox", NamespaceManager).Value
    with me
    textbox = ""
    end with

    usually in visual basic i can say textbox.clear() but that does not work in VSTA, also the code i posted does not clear it either. any ideas?

     

  • 07-10-2009 07:46 AM In reply to

    Re: clearing out a text box with code

    Hi--

    Infopath doesn't provide programatic access to the form controls, only the data. Not sure what your data field is named, but if it really is named 'textbox', and assuming that you are using VB.NET and InfoPath 2007 (since you specifiy VSTA) you'd want to use something like:

    Dim root As XPathNavigator = MainDataSource.CreateNavigator()           
    Dim textbox As XPathNavigator = root.SelectSingleNode("/my:myFields/my:textbox", NamespaceManager) 

    textbox.SetValue("")
    Hilary Stoupa

  • 07-10-2009 08:35 AM In reply to

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    Re: clearing out a text box with code

    Hi Hilary,

    thanks for your super-fast response. unfortunetly when i use your code, debugger gives me the following error.

    {"Operation is not valid due to the current position of the navigator."}

    any clue what that means?

    Thanks!

  • 07-10-2009 08:46 AM In reply to

    Re: clearing out a text box with code

    Interesting. It works in my sample form. What event are you using the code in? Is the name of your field that you are trying to set to blank really 'my:textbox'?

    Hilary Stoupa

  • 07-10-2009 10:08 AM In reply to

    Re: clearing out a text box with code

     The only way I can seem to reproduce that particular error is if I do SetValue("") directly on root (i.e. the object returned from MainDataSource.CreateNavigator() ).  Did you use Hilary's code exactly the way it is or did you modify it somehow?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-13-2009 05:19 AM In reply to

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    Re: clearing out a text box with code

    oh i figured it out, my code was not exactly the same as hillary's. dumb mistake actually, the code worked perfectly, thanks!

  • 06-29-2015 06:36 AM In reply to

    Re: clearing out a text box with code

    I tried your method for setting the value but it didn't work for me :/ (This worked after some more testing.)
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.