message box with text field, is it possible? - InfoPath Dev
in

InfoPath Dev

message box with text field, is it possible?

Last post 10-24-2008 06:27 AM by Bhavesh. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-09-2008 04:32 AM

    message box with text field, is it possible?

     Hi,

    I would like to create some sort of a message box that pops up, asking the user to confirm if a some infomation is correct, if they choose 'No' then i would like a new dialgue box with a text box inside asking them to enter the correct information.

    I can do the first part which is just a basic messagebox with yesno for the buttons, its the creation of the new dialog box with text field that i cant do.

     

    Thanks,

     

    Craig.

     

  • 10-10-2008 06:27 AM In reply to

    Re: message box with text field, is it possible?

    This does not really work with popup boxes.

    You need to use an extra view instead.

    So if the conditionas are correct execute a view switch.

    Setup the view however you want.

    If yes they return tot he previous view, if no the text box appears and once data is entered a continue or what ever button appears and when clicked they proceed to the next view.

  • 10-23-2008 07:00 AM In reply to

    • Bhavesh
    • Top 500 Contributor
      Male
    • Joined on 05-01-2008
    • Atlanta
    • Posts 40

    Re: message box with text field, is it possible?

    Hi,

    What you can do is keep a section with a set of buttons and a readonly text box containing a message on the top of the form. Make it hidden initially and as per the requirement set it visible to the user by creating some conditional formatting. This section will display the message to the user with two buttons. You keep one more section which will be displayed on the click of NO from the previous section. Now when user click NO from first section, you conditionally make it hidden and display the second section visible containing a entry field for the user.

    When user entry corrected information in the second section and click OK button, you can make that section hidden and have original screen.

    For making the sections hidden and visible to the user you need to keep couple of field in data source which may be of boolean type and act as a flag for making sections visible and hidden to the user.

    Hope this will help you in solving your problem.

    Bhavesh

  • 10-24-2008 12:44 AM In reply to

    Re: message box with text field, is it possible?

    Yes, what you describe is entirely possible if you're coding in C# or VB, but it requires a moderate understanding of windows form programming, and as the previous two posters have said, you'd probably be better off accomplishing this within InfoPath, without using dialogs.

     Nonetheless, here's a simple example in C# to get you started.  A real-life form would naturally be a bit more complex.:

    Create an InfoPath form with one text box (bound to "my:myFields/my:field1") and a button.

    In Tools->Form Options...->Programming, choose C# as the programming language.

    Open VSTA. (Tools->Programming->Microsoft Visual Studio Tools for Applications)

    Select "Add Windows Form..." from the Project menu.  Select "Windows Form" from the dialog that pops up, leave the filename as Form1.cs, and click Add

    A new blank windows form will be created.  Now from the Toolbox (to the left), drag one TextBox and one Button onto your form.  Notice that when you click the TextBox, the Properties window shows its name as textBox1.

    Now double-click the button.  This will open up the code view and position your cursor inside the Button's event handler.  Add the following code to that event handler:

       DialogResult = DialogResult.OK;
       Close();

    This tells the form to close when the button is clicked.

    One last thing you need to do is add a property to allow your InfoPath form code to access the TextBox's value.  Beneath the closing brace of the Button's event handler, add the following code:

       public string TextBoxValue
       {
          get
          {
             return textBox1.Text;
          }
       }

    So that that area of the code looks like:

       private void button1_Click(object sender, EventArgs e)
       {
          DialogResult =
    DialogResult.OK;
          Close();
       }
       public string TextBoxValue
       {
          get
          {
             return textBox1.Text;
          }
       }

    If you did that all correctly, that's all that you need to do to the windows form.  Save the file.

    Now go back to your InfoPath form.  Double-click its button, and click "Edit form code..."

    Add this code to the button's event handler:

       // this line creates an instance of the dialog
      
    Form1 dialog = new Form1();
      
    // this line opens up the dialog, and causes this code to wait until it is closed
      
    dialog.ShowDialog();
      
    // this line selects the /my:myFields/my:field1 node from your data source
      
    XPathNavigator node = MainDataSource.CreateNavigator().SelectSingleNode("my:myFields/my:field1",NamespaceManager);
      
    // this line assigns the contents of the dialog to field1
      
    node.SetValue(dialog.TextBoxValue);

    Now preview the form and try it out.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-24-2008 01:38 AM In reply to

    Re: message box with text field, is it possible?

     Thanks to everyone for your ideas. Jimmy, that worked perfect, i didn't know that windows forms could be added to the infopath project.

    Thanks again,

     

    Craig.

     

  • 10-24-2008 02:33 AM In reply to

    Re: message box with text field, is it possible?

    Yeah, it's great that Office files can now run practically any code that any other .NET application can run.

    Glad I could help!

    Jimmy

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

    • Bhavesh
    • Top 500 Contributor
      Male
    • Joined on 05-01-2008
    • Atlanta
    • Posts 40

    Re: message box with text field, is it possible?

    Jimmy this is really a great solution.

    Bhavesh

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