To use code to control whether or not a section in your view displays or hides, you'll want to use xdExtension. Search for this in the forum or on our site. There are 3 How To articles and 3 posts on this topic. Happy reading!
Patrick Halstead [InfoPath MVP]
InfoPathDev
Patrick Halstead
Project Manager at Qdabra