Programmatically set properties on InfoPath controls
Learn why you can only use conditional formatting on controls to programmatically set properties to hide, disable, or change the color for InfoPath controls.
I’ve written about this before, but think that the topic lends itself for a repeat post, because I’ve seen many of the visitors to my site searching for answers to questions such as:
- how to hide first row by programmatically infopath
- how to change infopath textbox colour programmatically
Using conditional formatting to set properties
Whether you want to:
- programmatically make an InfoPath control read-only
- programmatically hide an InfoPath control
- programmatically change the background color of an InfoPath control
- programmatically change the color of the text in an InfoPath control
you have to use Conditional Formatting to do so.
Programming in InfoPath is different to programming in Visual Studio. InfoPath controls do not have properties you can set at run-time through code. The only properties you can set are properties that are inherent to XML nodes.
Checking the availability of properties on an InfoPath control
If you want to programmatically set a property such as Enabled, Visible, BackgroundColor, Color, ReadOnly, etc. you first have to check whether an equivalent InfoPath conditional formatting setting is available for such a property.
You can do this by:
- Double-clicking on the control to open its Properties dialog box.
- Look for a Conditional Formatting button on the Properties dialog box; it is usually located on the Display tab.
- Open the Conditional Formatting dialog box and check whether it offers a setting that you can use for the property you want to programmatically set.
Creating a hidden field to use for setting properties through code
The logic behind using a hidden field to programmatically set a property on an InfoPath control is that you have to create a condition so that the conditional formatting on the control can be activated. And one way of doing this is by programmatically setting the value of a field on which the conditional formatting depends.
And since the field you’d be using is only to manipulate the visual aspects of controls, you don’t want users to actually see this field, which is why you should make it hidden.
I thought it would be good to show you step-by-step how to implement such a solution, so have gone ahead and written an article on how to programmatically hide the first row of a repeating table in infopath. Enjoy!
Related Posts
Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. Usage of techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.


