コード例 #1
0
 public void TestChangeBusinessObjectUpdatesComboBox()
 {
     //---------------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 ----------------------
     s.SampleText = "Four";
     mapper.UpdateControlValueFromBusinessObject();
     //---------------Test Result -----------------------
     Assert.AreEqual("Four", cbx.SelectedItem, "Value is not set.");
 }
コード例 #2
0
        /// <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 ");
                    }
                };
        }