diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 4fb87d7e5..0483d82e7 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -5,10 +5,10 @@ // Ross Ferguson (ross.c.ferguson@btinternet.com) // +using NStack; using System; using System.Collections; using System.Collections.Generic; -using NStack; namespace Terminal.Gui { /// @@ -39,10 +39,7 @@ namespace Terminal.Gui { private void Initialize (ComboBox container, bool hideDropdownListOnClick) { - if (container == null) - throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); - - this.container = container; + this.container = container ?? throw new ArgumentNullException (nameof(container), "ComboBox container cannot be null."); HideDropdownListOnClick = hideDropdownListOnClick; } @@ -236,7 +233,7 @@ namespace Terminal.Gui { readonly TextField search; readonly ComboListView listview; bool autoHide = true; - int minimumHeight = 2; + readonly int minimumHeight = 2; /// /// Public constructor @@ -721,7 +718,19 @@ namespace Terminal.Gui { return text; } set { - search.Text = text = value; + SetSearchText (value); + } + } + + /// + /// Current search text + /// + public ustring SearchText { + get { + return search.Text; + } + set { + SetSearchText (value); } } @@ -775,7 +784,7 @@ namespace Terminal.Gui { private void Reset (bool keepSearchText = false) { if (!keepSearchText) { - search.Text = text = ""; + SetSearchText (string.Empty); } ResetSearchSet (); @@ -788,6 +797,11 @@ namespace Terminal.Gui { } } + private void SetSearchText (ustring value) + { + search.Text = text = value; + } + private void ResetSearchSet (bool noCopy = false) { searchset.Clear (); @@ -843,7 +857,7 @@ namespace Terminal.Gui { listview.SetSource (searchset); listview.Clear (); // Ensure list shrinks in Dialog as you type listview.Height = CalculatetHeight (); - this.SuperView?.BringSubviewToFront (this); + SuperView?.BringSubviewToFront (this); } /// @@ -857,7 +871,7 @@ namespace Terminal.Gui { OnOpenSelectedItem (); } var rect = listview.ViewToScreen (listview.Bounds); - Reset (SelectedItem > -1); + Reset (keepSearchText: true); listview.Clear (rect); listview.TabStop = false; SuperView?.SendSubviewToBack (this);