AjaxControlToolkit.ComboBox.InsertItem C# (CSharp) Méthode

InsertItem() protected méthode

protected InsertItem ( ComboBoxItemInsertEventArgs e ) : void
e ComboBoxItemInsertEventArgs
Résultat void
        protected virtual void InsertItem(ComboBoxItemInsertEventArgs e)
        {
            if(!e.Cancel) {
                var insertIndex = -1;

                if(e.InsertLocation == ComboBoxItemInsertLocation.Prepend)
                    insertIndex = 0;
                else if(e.InsertLocation == ComboBoxItemInsertLocation.Append)
                    insertIndex = Items.Count;
                else if(e.InsertLocation == ComboBoxItemInsertLocation.OrdinalText) {
                    // loop through items collection to find proper insertion point
                    insertIndex = 0;
                    foreach(ListItem li in Items) {
                        var compareValue = String.Compare(e.Item.Text, li.Text, StringComparison.Ordinal);
                        if(compareValue > 0)
                            ++insertIndex;
                        else
                            break;
                    }
                }
                else if(e.InsertLocation == ComboBoxItemInsertLocation.OrdinalValue) {
                    // loop through items collection to find proper insertion point
                    insertIndex = 0;
                    foreach(ListItem li in Items) {
                        var compareValue = String.Compare(e.Item.Value, li.Value, StringComparison.Ordinal);
                        if(compareValue > 0)
                            ++insertIndex;
                        else
                            break;
                    }
                }

                if(insertIndex >= Items.Count) {
                    Items.Add(e.Item);
                    SelectedIndex = Items.Count - 1;
                } else {
                    Items.Insert(insertIndex, e.Item);
                    SelectedIndex = insertIndex;
                }
                OnItemInserted(e);
            }
        }