/// <summary> /// Adds an ItemSelected event handler. /// For Windows Forms you may want the business object to be updated immediately, however /// for a web environment with low bandwidth you may choose to only update when the user saves. ///</summary> public void AddItemSelectedEventHandler(ListComboBoxMapper mapper) { var comboBoxWin = mapper.GetControl() as ComboBox; if (comboBoxWin == null) return; comboBoxWin.SelectedIndexChanged += delegate { try { mapper.ApplyChangesToBusinessObject(); mapper.UpdateControlValueFromBusinessObject(); } catch (Exception ex) { GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error "); } }; }
public void TestSetComboBoxUpdatesBO() { //---------------Set up test pack------------------- IComboBox cbx = GetControlFactory().CreateComboBox(); const string propName = "SampleText"; ListComboBoxMapper mapper = new ListComboBoxMapper(cbx, propName, false, GetControlFactory()); mapper.SetList("One|Two|Three|Four"); Sample s = new Sample(); s.SampleText = "Three"; mapper.BusinessObject = s; //---------------Execute Test ---------------------- cbx.SelectedIndex = 0; mapper.ApplyChangesToBusinessObject(); //---------------Test Result ----------------------- Assert.AreEqual(cbx.SelectedItem, s.SampleText, "BO property value isn't changed when control value is changed."); }