Accessing controls in C# - InfoPath Dev
in

InfoPath Dev

Accessing controls in C#

Last post 02-20-2009 07:24 AM by Jimmy. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-20-2009 02:13 AM

    • yoni_R
    • Not Ranked
    • Joined on 02-20-2009
    • Posts 7

    Accessing controls in C#

     Hi,

     

    we're trying to make a form (not browser enabled as we are using an mutiple selection listbox) that will enable us to choose a bunch of members. Those members need to receive an email after the send-button is pressed.

    The problem we have is that we can't find a way to access the content of the controls in de form in our code in C#.

     

    Can anyone tell us what we can do to make this happen?

     

    thx

  • 02-20-2009 02:52 AM In reply to

    Re: Accessing controls in C#

    In InfoPath we don't access a form's controls directly, but by accessing the XML document represented by the main data source.  An InfoPath form is just a visual representation of an XML document. So if I had a textbox bound to a field with the path myFields/field1, I could change its value like this:

    XPathNavigator mainDataNavigator = MainDataSource.CreateNavigator();
    mainDataNavigator.SelectSingleNode(
    "/my:myFields/my:field1", NamespaceManager).Value = "Hey!";

    If you are not yet familiar with the XPathNavigator class, I recommend reading up on it a bit.

    http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.aspx

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-20-2009 02:59 AM In reply to

    • yoni_R
    • Not Ranked
    • Joined on 02-20-2009
    • Posts 7

    Re: Accessing controls in C#

     Ok, will try that again then! :)

    But the problem was that when we did that we got "KeyNotFoundException".

  • 02-20-2009 05:27 AM In reply to

    Re: Accessing controls in C#

    If you post the code you're trying to use, we might be able to figure out what's going wrong.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-20-2009 05:46 AM In reply to

    • yoni_R
    • Not Ranked
    • Joined on 02-20-2009
    • Posts 7

    Re: Accessing controls in C#

    for the moment, something as simple as

    public void CTRL50_5_Clicked(object sender, ClickedEventArgs e)

    {

    XPathNavigator mainDataSource = MainDataSource.CreateNavigator();

    Console.WriteLine(mainDataSource.SelectSingleNode("/my:Fields/my:bericht", NamespaceManager).Value); Console.ReadLine();

    }

     

    is giving us a NullReferenceException.

  • 02-20-2009 07:18 AM In reply to

    Re: Accessing controls in C#

    it must be mainDataNavigator.SelectSingleNode("/my:myFields/my:bericht", NamespaceManager).Value)

    you placed /my:Fields in place of /my:myFields..check out 

     

  • 02-20-2009 07:24 AM In reply to

    Re: Accessing controls in C#

    I don't think using Console.WriteLine() and Console.ReadLine() is going to do much.  There is no console in an InfoPath form.

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