diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 60055472..2cf4f138 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -255,7 +255,7 @@ namespace Netch.Forms private void SaveConfigs() { Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex; - if (ModeComboBox.SelectedItem != null) + if (ModeComboBox.Items.Count!=0 && ModeComboBox.SelectedItem != null) { if (ModeComboBox.Tag is object[] list) diff --git a/Netch/Netch.cs b/Netch/Netch.cs index 4fe5ea72..13f5f49e 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -1,5 +1,4 @@ -using Microsoft.Win32; -using System; +using System; using System.Globalization; using System.IO; using System.Text; @@ -122,8 +121,11 @@ namespace Netch public static void Application_OnException(object sender, ThreadExceptionEventArgs e) { - MessageBox.Show(e.Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - Application.Exit(); + if (!e.Exception.ToString().Contains("ComboBox")) + { + MessageBox.Show(e.Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + //Application.Exit(); } } } diff --git a/NetchLib/SearchComboBox.cs b/NetchLib/SearchComboBox.cs index 0e3d4ef0..2065f000 100644 --- a/NetchLib/SearchComboBox.cs +++ b/NetchLib/SearchComboBox.cs @@ -82,69 +82,76 @@ namespace System.Windows.Forms private object[] newList; private void ReevaluateCompletionList() { - var currentSearchTerm = Text.ToLowerInvariant(); - if (currentSearchTerm == _previousSearchTerm) return; - - _previousSearchTerm = currentSearchTerm; try { - SuspendLayout(); - - var originalList = (object[])Tag; - if (originalList == null) - { - Tag = originalList = Items.Cast().ToArray(); - } - - if (string.IsNullOrEmpty(currentSearchTerm)) - { - if (Items.Count == originalList.Length) return; - - newList = originalList; - } - else - { - newList = originalList.Where(x => x.ToString().ToLowerInvariant().Contains(currentSearchTerm)).ToArray(); - } + var currentSearchTerm = Text.ToLowerInvariant(); + if (currentSearchTerm == _previousSearchTerm) return; + _previousSearchTerm = currentSearchTerm; try { - while (Items.Count > 0) + SuspendLayout(); + + var originalList = (object[])Tag; + if (originalList == null) { - Items.RemoveAt(0); + Tag = originalList = Items.Cast().ToArray(); } - } - catch - { + + if (string.IsNullOrEmpty(currentSearchTerm)) + { + if (Items.Count == originalList.Length) return; + + newList = originalList; + } + else + { + newList = originalList.Where(x => x.ToString().ToLowerInvariant().Contains(currentSearchTerm)).ToArray(); + } + try { - Items.Clear(); + while (Items.Count > 0) + { + Items.RemoveAt(0); + } } catch { - // ignored + try + { + Items.Clear(); + } + catch + { + // ignored + } } - } - Items.AddRange(newList.ToArray()); + Items.AddRange(newList.ToArray()); + } + finally + { + if (currentSearchTerm.Length >= 2 && !DroppedDown) + { + DroppedDown = true; + Cursor.Current = Cursors.Default; + Text = currentSearchTerm; + Select(currentSearchTerm.Length, 0); + } + + if (Items.Count > 0) + { + DroppedDown = false; + DroppedDown = true; + } + + ResumeLayout(true); + } } - finally + catch { - if (currentSearchTerm.Length >= 2 && !DroppedDown) - { - DroppedDown = true; - Cursor.Current = Cursors.Default; - Text = currentSearchTerm; - Select(currentSearchTerm.Length, 0); - } - - if (Items.Count > 0) - { - DroppedDown = false; - DroppedDown = true; - } - - ResumeLayout(true); + // ignored } } }