выпадающий список со списком вне диапазона исключений - PullRequest
0 голосов
/ 09 сентября 2018

Я пытался создать фильтр для выпадающего списка при вводе текста в него, и он отображает выпадающий список с соответствующими значениями из комбинированного списка, который я использовал здесь: C # Добавление фильтра к выпадающему списку в выпадающем списке Но язаметил, что когда я набираю символы, которые не имеют совпадающих значений в комбинированном списке, а затем нажимаю Enter или щелкаю мышью, он выдает тип исключения System.ArgumentOutOfRangeException и говорит, что InvalidArgument = Value это мой код:

private void comboBox1_TextUpdate(object sender, EventArgs e)
        {
            try
            {
                comboBox1.DroppedDown = true;
                Cursor.Current = Cursors.Default;
                string filter_param = comboBox1.Text;

                string[] filteredItems = Array.FindAll(arrProjectList, c => c.Contains(filter_param));  //'arrProjectList' is a global string array that holds and fills the combobox values
                // another variant for filtering using StartsWith:
                //List<string> filteredItems = arrProjectList.FindAll(x => x.StartsWith(filter_param));

                comboBox1.DataSource = filteredItems;

                if (string.IsNullOrWhiteSpace(filter_param))
                {
                    comboBox1.DataSource = filteredItems;
                }
                comboBox1.DroppedDown = true;

                // this will ensure that the drop down is as long as the list
                comboBox1.IntegralHeight = true;

                // remove automatically selected first item
                comboBox1.SelectedIndex = -1;

                comboBox1.Text = filter_param;

                // set the position of the cursor
                comboBox1.SelectionStart = filter_param.Length;
                comboBox1.SelectionLength = 0;

                //comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
                //comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            }
            catch
            {
                MessageBox.Show("error");
            }
        }

Я не нашел решения для этого в руководстве.Как это можно исправить?

...