I have info path form with three text boxes (tb1, tb2, tb3) and have calculated value field with (tb1+tb2+tb3).

Eg: If 1,2,3 are entered then it shows 6 in the calculated value field.

My Requirement:

If calculated value field is between 1-4 then it should show Low

If calculated value field is between 5-10 then it should show Medium

If calculated value field is between 11-14 then it should show High.

Now I need to Show whether it is Low/Medium/High based on the calculated value field on the info path form. Can anyone please explain step by step how to get it.


2 Answers 2


It is more correct to realize it with rules but it is a lot of typing so I made it with custom C# code.
In Infopath Designer 2010 create a form naming controls accordingly:

enter image description here

enter image description here

On ribbon click Developer tab click Changed Event button having chosen each of text boxes, verifying changes in the code in opened VSTA (Visual Studio Tools for Applications) upon each click.

Make changes according this code snippet:

using Microsoft.Office.InfoPath;  
using System; 
using System.Windows.Forms;  
using System.Xml;  
using System.Xml.XPath;  
using mshtml;  

namespace IP_Calculated_Value {

    public partial class FormCode
        int iTextBox1, iTextBox2, iTextBox3;
        XPathNavigator calculatedNode, textBox1Node, textBox2Node, textBox3Node; 
        public void InternalStartup()
            calculatedNode = this.MainDataSource.CreateNavigator().
                 SelectSingleNode("/my:myFields/my:Calculated", NamespaceManager);
                ("Enter integers into textboxes and click outside to see calculated value");

            textBox1Node = this.MainDataSource.CreateNavigator().
                SelectSingleNode("/my:myFields/my:TextBox1", NamespaceManager);
                SelectSingleNode("/my:myFields/my:TextBox2", NamespaceManager);
            textBox3Node = this.MainDataSource.CreateNavigator().
                SelectSingleNode("/my:myFields/my:TextBox3", NamespaceManager);

            EventManager.XmlEvents["/my:myFields/my:TextBox1"].Changed += 
                new XmlChangedEventHandler(TextBox1_Changed);
            EventManager.XmlEvents["/my:myFields/my:TextBox3"].Changed += 
                new XmlChangedEventHandler(TextBox3_Changed);
            EventManager.XmlEvents["/my:myFields/my:TextBox2"].Changed += 
                new XmlChangedEventHandler(TextBox2_Changed);
        public void TextBox1_Changed(object sender, XmlEventArgs e)
            iTextBox1 = Convert.ToInt32(textBox1Node.Value);
        public void TextBox2_Changed(object sender, XmlEventArgs e)
            iTextBox2 = Convert.ToInt32(textBox2Node.Value);
        public void TextBox3_Changed(object sender, XmlEventArgs e)
            iTextBox3 = Convert.ToInt32(textBox3Node.Value);
        public void ShowCalculated()
            int sum = iTextBox1 + iTextBox2 + iTextBox3;
            calculatedNode.SetValue("Outside of permitted sum range");
            if (sum >= 1 && sum <= 4) calculatedNode.SetValue("Low");
            if (sum >= 5 && sum <= 10) calculatedNode.SetValue("Medium");
            if (sum >= 11 && sum < 14) calculatedNode.SetValue("High");
    }   }

just add 3 calculated fields with text low, medium and high. on each calculated field add a formatting rule. the formatting rule hides the calculted field if it's not a low/medium/high value.

Calculated Field A: Value = Low, rule: hide when calculatedValue > 4 or calculatedValue < 1 Calculated Field B: Value = Medium, rule: hide when calculatedValue < 5 or calculatedValue > 10 Calculated Field C: Value = High, rule: hide when calculatedValue < 11 or calculatedValue > 14

Hope i got it right. Maybe you have to set the calculatedfield with a rule too. I think c#-code is not necessary here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.