Habanero.Faces.Win.ListComboBoxMapperStrategyWin.AddItemSelectedEventHandler C# (CSharp) Method

AddItemSelectedEventHandler() public method

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.
public AddItemSelectedEventHandler ( ListComboBoxMapper mapper ) : void
mapper Habanero.Faces.Base.ListComboBoxMapper
return void
        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 ");
                    }
                };
        }
    }

Usage Example

 public void Test_AddItemSelectedEventHandler_WhenMapperUsingHabaneroControl_ShouldAddBehaviours()
 {
     //---------------Set up test pack-------------------
     var cmbWin = new ComboBoxWin() { Name = "TestComboBox", Enabled = true };
     var comboBoxMapper = new ListComboBoxMapperStub(cmbWin);
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf<IComboBox>(comboBoxMapper.Control);
     //---------------Execute Test ----------------------
     var comboBoxStrategyWin = new ListComboBoxMapperStrategyWin();
     comboBoxStrategyWin.AddItemSelectedEventHandler(comboBoxMapper);
     //---------------Assert Result----------------------
     Assert.IsTrue(true, "If an error was not thrown then we are OK");
 }
All Usage Examples Of Habanero.Faces.Win.ListComboBoxMapperStrategyWin::AddItemSelectedEventHandler
ListComboBoxMapperStrategyWin