InfoPath: Drop-Down List Changed, Switch View

Web know, switch available in Button rule. Sometime, we need to switch view when InfoPath form data changed like Drop-Down List Changed Event. What’re We going to do?

We must implement FormEvents.ContextChanged and DropDown Changed. In FormEvents.ContextChanged we call

ViewInfos.SwitchView(viewname);

Here is my code

public void InternalStartup()
        {         
            EventManager.FormEvents.ContextChanged += new ContextChangedEventHandler(FormEvents_ContextChanged);
            EventManager.XmlEvents["/my:DoanhNghieps/my:loaiHinhHoatDong"].Changed += new XmlChangedEventHandler(loaiHinhHoatDong_Changed);
        }

        public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)
        {          
            if (canRedirect)
            {
                canRedirect = false;
                ViewInfos.SwitchView("CN");
            }
        }
        private bool canRedirect = false;
        public void loaiHinhHoatDong_Changed(object sender, XmlEventArgs e)
        {
            // Write your code here to change the main data source.
            canRedirect = true;           
        } 

Leave a Reply