Hey!

Attached is a patch that implements support for ComboBox.

The idea is to use the available support in TextBox, so the TextBox has
direct access to our items. Since this is not the clearest approach,
it's the better in terms of performance, since otherwise we should
create a IList of item's text, and modifying or updating it as items are
modified in ComboBox.Items collection.

Observe that this patch only makes use of the basic properties of Auto
complete in TextBox. As soon as I check in the keyboard navigation in
TextBox for automplete, I will come with a second patch for ComboBox ;-)

Carlos.
Index: ComboBox.cs
===================================================================
--- ComboBox.cs	(revisión: 106985)
+++ ComboBox.cs	(copia de trabajo)
@@ -246,6 +246,8 @@
 
 				if(auto_complete_custom_source != null)
 					auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
+
+				SetTextBoxAutoCompleteData ();
 			}
 		}
 
@@ -263,6 +265,7 @@
 					throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteMode", value));
 
 				auto_complete_mode = value;
+				SetTextBoxAutoCompleteData ();
 			}
 		}
 
@@ -280,8 +283,27 @@
 					throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteSource", value));
 
 				auto_complete_source = value;
+				SetTextBoxAutoCompleteData ();
 			}
 		}
+
+		void SetTextBoxAutoCompleteData ()
+		{
+			if (textbox_ctrl == null)
+				return;
+
+			textbox_ctrl.AutoCompleteMode = auto_complete_mode;
+
+			if (auto_complete_source == AutoCompleteSource.ListItems) {
+				textbox_ctrl.AutoCompleteSource = AutoCompleteSource.CustomSource;
+				textbox_ctrl.AutoCompleteCustomSource = null;
+				textbox_ctrl.AutoCompleteInternalSource = this;
+			} else {
+				textbox_ctrl.AutoCompleteSource = auto_complete_source;
+				textbox_ctrl.AutoCompleteCustomSource = auto_complete_custom_source;
+				textbox_ctrl.AutoCompleteInternalSource = null;
+			}
+		}
 #endif
 		public override Color BackColor {
 			get { return base.BackColor; }
@@ -433,6 +455,9 @@
 
 					if (IsHandleCreated == true)
 						Controls.AddImplicit (textbox_ctrl);
+#if NET_2_0
+					SetTextBoxAutoCompleteData ();
+#endif
 				}
 				
 				ResumeLayout ();
Index: TextBox.cs
===================================================================
--- TextBox.cs	(revisión: 106985)
+++ TextBox.cs	(copia de trabajo)
@@ -27,6 +27,7 @@
 // NOT COMPLETE
 
 using System;
+using System.Collections;
 using System.ComponentModel;
 using System.ComponentModel.Design;
 using System.Drawing;
@@ -58,6 +59,7 @@
 		private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
 		private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
 		private AutoCompleteListBox auto_complete_listbox;
+		private ComboBox auto_complete_cb_source;
 #endif
 		#endregion	// Variables
 
@@ -121,8 +123,14 @@
 				return;
 
 			// We only support CustomSource by now
+			IList source;
+			if (auto_complete_cb_source == null)
+				source = auto_complete_custom_source;
+			else
+				source = auto_complete_cb_source.Items;
+
 			if (auto_complete_source != AutoCompleteSource.CustomSource ||
-				auto_complete_custom_source == null || auto_complete_custom_source.Count == 0)
+				source == null || source.Count == 0)
 				return;
 
 			if (Text.Length == 0) {
@@ -142,10 +150,14 @@
 
 			string text = Text;
 			auto_complete_listbox.Items.Clear ();
-			foreach (string str in auto_complete_custom_source)
-				if (str.StartsWith (text, StringComparison.CurrentCultureIgnoreCase))
-					auto_complete_listbox.Items.Add (str);
 
+			for (int i = 0; i < source.Count; i++) {
+				string item_text = auto_complete_cb_source == null ? auto_complete_custom_source [i] :
+					auto_complete_cb_source.GetItemText (auto_complete_cb_source.Items [i]);
+				if (item_text.StartsWith (text, StringComparison.CurrentCultureIgnoreCase))
+					auto_complete_listbox.Items.Add (item_text);
+			}
+
 			IList<string> matches = auto_complete_listbox.Items;
 			if ((matches.Count == 0) ||
 				(matches.Count == 1 && matches [0].Equals (text, StringComparison.CurrentCultureIgnoreCase))) { // Exact single match
@@ -159,6 +171,15 @@
 			auto_complete_listbox.Location = PointToScreen (new Point (0, Height));
 			auto_complete_listbox.ShowListBox ();
 		}
+
+		internal ComboBox AutoCompleteInternalSource {
+			get {
+				return auto_complete_cb_source;
+			}
+			set {
+				auto_complete_cb_source = value;
+			}
+		}
 #endif
 
 		private void UpdateAlignment ()
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to