Exemple #1
0
        /// <summary>Internal delegate to handle adding new string to items.</summary>
        /// <param name="sender">The sender value.</param>
        /// <param name="expandableStringComboBoxEvent">The expandableStringComboBoxEvent value.</param>
        private static void AddToListEvent(object sender, ExpandableStringComboBoxEvent expandableStringComboBoxEvent)
        {
            var ctrl = (ExpandableStringComboBox)sender;

            if (ctrl.ListTerminator != null)
            {
                ctrl.Items.Insert(ctrl.Items.Count - 1, expandableStringComboBoxEvent.Input); // combo will sort automatically, if Sort=true
            }
            else
            {
                ctrl.Items.Add(expandableStringComboBoxEvent.Input);
            }
        }
Exemple #2
0
        /// <summary>Internal handler to handle user selection. The method triggers GetNewStringEvent if user selects the ListTerminator-option.</summary>
        /// <param name="sender">The sender value.</param>
        /// <param name="eventArgs">The eventArgs value.</param>
        private void SelectionChangeCommittedHandler(object sender, EventArgs eventArgs)
        {
            if (this.ListTerminator != null && this.ListTerminator.Equals(this.SelectedItem))
            {
                var    previousValue = (-1 != this.previousIndex) ? this.Items[this.previousIndex] as string : string.Empty;
                string result        = null;

                if (this.GetNewStringEvent != null)
                {
                    var newEvent = new ExpandableStringComboBoxEvent(previousValue);
                    this.GetNewStringEvent(this, newEvent);
                    result = newEvent.Result;
                }

                if (result != null)
                {
                    if (!this.Items.Contains(result))
                    {
                        // add only if value not in the list
                        this.AddNewString(result);
                    }

                    this.SelectedIndex = this.previousIndex = this.Items.IndexOf(result);

                    this.Text = result;
                }
                else
                {
                    // restore previous
                    this.SelectedIndex = this.previousIndex;
                }
            }
            else
            {
                this.previousIndex = this.SelectedIndex;
            }
        }