Beispiel #1
0
        // event handler for secondary type combobox DropDownClosed event
        private void secondaryTypeComboBox_DropDownClosed(object sender, EventArgs e)
        {
            // if the type was deleted from primary type combobox insert it back and reset variable
            if (DeletedTypeFromPrimaryCombobox != null)
            {
                PrimaryPkmnTypeList.Insert(IndexOfDeletedPrimaryType, DeletedTypeFromPrimaryCombobox);
                DeletedTypeFromPrimaryCombobox = null;
            }

            // helper variable
            var selectedSecondaryType = secondaryTypeComboBox.SelectedItem as IPkmnType;

            // if selected secondarytype is not "(none)" delete it from primarytype list and save to "Deleted" properties
            if (!(selectedSecondaryType is EmptyPkmnType))
            {
                DeletedTypeFromPrimaryCombobox = PrimaryPkmnTypeList.Where(i => i.TypeName == selectedSecondaryType.TypeName).FirstOrDefault();
                IndexOfDeletedPrimaryType      = PrimaryPkmnTypeList.IndexOf(DeletedTypeFromPrimaryCombobox);
                PrimaryPkmnTypeList.Remove(PrimaryPkmnTypeList.Where(i => i.TypeName == selectedSecondaryType.TypeName).FirstOrDefault());
            }

            // refresh primarytype combobox
            primaryTypeComboBox.DataSource = null;
            primaryTypeComboBox.DataSource = PrimaryPkmnTypeList;

            // if something was selected in primary combobox select it again after combobox refreshed and possibly changed index
            if (DeletedTypeFromSecondaryCombobox != null)
            {
                primaryTypeComboBox.SelectedIndex = PrimaryPkmnTypeList.
                                                    IndexOf(PrimaryPkmnTypeList.
                                                            Where(i => i.TypeName == DeletedTypeFromSecondaryCombobox.TypeName).FirstOrDefault());
            }
        }
Beispiel #2
0
        public IndexModel(ILogger <IndexModel> logger)
        {
            _logger = logger;

            // add empty pkmn types to the comboboxes
            PrimaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType());
            SecondaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType());
        }
Beispiel #3
0
        // form constructor
        public PokemonTypeCalculatorForm()
        {
            InitializeComponent();

            // add empty pkmn types to the comboboxes
            PrimaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType());
            SecondaryPkmnTypeList.Insert(0, PkmnTypeFactory.CreateEmptyPkmnType());

            // set the collection properties as datasources for the comboboxes
            primaryTypeComboBox.DataSource   = PrimaryPkmnTypeList;
            secondaryTypeComboBox.DataSource = SecondaryPkmnTypeList;

            // set the name of the pokemon type as a displayed value for comboboxes
            primaryTypeComboBox.DisplayMember   = "TypeName";
            secondaryTypeComboBox.DisplayMember = "TypeName";

            // set the collection for list view
            pkmnTypeObjectListView.SetObjects(PkmnTypeList);

            // set focus on damage taken button
            showDamageTakenButton.Select();
        }