예제 #1
0
        // add given string to ComboBox at beginning
        private void MonitorExtDropdownInsert(string str)
        {
            // check that string isn't empty
            if (str.Length <= 0)
            {
                return;
            }

            // convert str to lowercase
            str = str.ToLower();

            // pull Items from control
            ComboBox.ObjectCollection extComboList = ComboBoxMonitorExt.Items;

            // check that string is not equal to current value at beginning
            // check if list contains anything
            // could use IndexOf(str), but don't want to deal with if it starts at the end or beginning of the collection
            if (extComboList.Count > 0)
            {
                // check if equals, return
                if (str == (string)extComboList[0])
                {
                    return;
                }
            }

            // if size is at max, remove last entry
            if (extComboList.Count == extHistoryMax)
            {
                extComboList.RemoveAt(extComboList.Count - 1);
            }

            // insert at beginning
            extComboList.Insert(0, str);
        }
예제 #2
0
 private void maintainHistoryLength(ComboBox.ObjectCollection items)
 {
     if (items.Count > DEFAULT_MAX_HISTORY)
     {
         int lastIndex = items.Count - 1;
         items.RemoveAt(lastIndex);
     }
 }
예제 #3
0
        /// <summary>
        /// Perform the save operation to save the friend's data
        /// </summary>
        /// <returns>true if succeeded, false if not succeeded</returns>
        private bool PerformSaveOp()
        {
            // Check if saving is valid
            bool notValid = string.IsNullOrWhiteSpace(this.friendSheet.Friend.Name);

            if (notValid)
            {
                MessageBox.Show(
                    "Saving failed, name cannot be empty or only have whitespace",
                    "Cannot save",
                    MessageBoxButtons.OK);
                return(false);
            }

            // Save friend sheet
            this.friendSheet.SaveFriend();

            // Save lists
            this.listBring.SaveItemList();
            this.listWant.SaveItemList();

            Friend friend = this.friendSheet.Friend;

            friend.ListBring = this.listBring.Items;
            friend.ListWant  = this.listWant.Items;

            int index = this.ComboBoxFriends.SelectedIndex;

            ComboBox.ObjectCollection items = this.ComboBoxFriends.Items;

            if (index == -1)
            {
                // If index is -1 (new entry) then prepare the index to be 0 for later insertion
                index = 0;
            }
            else
            {
                // If index is something other than -1 (existing entry), remove the entry at that index
                // (supposedly the friend object with "outdated" params) to have the new friend entry
                // be added in as a replacement.
                items.RemoveAt(index);
            }

            // Insert the friend object at the designated index
            items.Insert(index, friend);

            // Have the combo box select the entry corresponding to that index
            this.ComboBoxFriends.SelectedIndex = index;

            return(true);
        }