Thứ Hai, 15 tháng 6, 2009

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:

   1: public void InternalStartup()
   2:         {          
   3:             EventManager.FormEvents.ContextChanged += new ContextChangedEventHandler(FormEvents_ContextChanged);
   4:             EventManager.XmlEvents["/my:DoanhNghieps/my:loaiHinhHoatDong"].Changed += new XmlChangedEventHandler(loaiHinhHoatDong_Changed);
   5:         } 
   6:  
   7:         public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)
   8:         {           
   9:             if (canRedirect) 
  10:             { 
  11:                 canRedirect = false; 
  12:                 ViewInfos.SwitchView("CN"); 
  13:             }
  14:         }
  15:         private bool canRedirect = false;
  16:         public void loaiHinhHoatDong_Changed(object sender, XmlEventArgs e)
  17:         {
  18:             // Write your code here to change the main data source.
  19:             canRedirect = true;            
  20:         }

Không có nhận xét nào:

Đăng nhận xét