using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
+using System.Diagnostics;
namespace System.Windows.Forms
{
return;
}
- // do nothing if value exactly matches text of selected item
- if (SelectedItem != null && string.Compare (value, GetItemText (SelectedItem), false, CultureInfo.CurrentCulture) == 0)
- return;
-
- // find exact match using case-sensitive comparison, and if does
- // not result in any match then use case-insensitive comparison
- int index = FindStringExact (value, -1, false);
- if (index == -1) {
- index = FindStringExact (value, -1, true);
- }
- if (index != -1) {
- SelectedIndex = index;
- return;
+ // don't set the index if value exactly matches text of selected item
+ if (SelectedItem == null || string.Compare (value, GetItemText (SelectedItem), false, CultureInfo.CurrentCulture) != 0)
+ {
+ // find exact match using case-sensitive comparison, and if does
+ // not result in any match then use case-insensitive comparison
+ int index = FindStringExact (value, -1, false);
+ if (index == -1) {
+ index = FindStringExact (value, -1, true);
+ }
+ if (index != -1) {
+ SelectedIndex = index;
+ return;
+ }
}
- // set directly the passed value, since we already know it's not matching any item
+ // set directly the passed value
if (dropdown_style != ComboBoxStyle.DropDownList)
textbox_ctrl.Text = value;
}
base.OnDataSourceChanged (e);
BindDataItems ();
+ /**
+ ** This 'Debugger.IsAttached' hack is here because of
+ ** Xamarin Bug #2234, which noted that when changing
+ ** the DataSource, in Windows exceptions are eaten
+ ** when SelectedIndexChanged is fired. However, when
+ ** the debugger is running (i.e. in MonoDevelop), we
+ ** want to be alerted of exceptions.
+ **/
+
+ if (Debugger.IsAttached) {
+ SetSelectedIndex ();
+ } else {
+ try {
+ SetSelectedIndex ();
+ } catch {
+ //ignore exceptions here per
+ //bug 2234
+ }
+ }
+ }
+
+ private void SetSelectedIndex ()
+ {
if (DataSource == null || DataManager == null) {
SelectedIndex = -1;
}
if (index == owner.SelectedIndex) {
if (owner.textbox_ctrl == null)
owner.Refresh ();
- else
- owner.textbox_ctrl.SelectedText = value.ToString ();
+ else {
+ owner.textbox_ctrl.Text = value.ToString ();
+ owner.textbox_ctrl.SelectAll ();
+ }
}
}
}
{
if (value == null)
return;
-
- if (IndexOf (value) == owner.SelectedIndex)
- owner.SelectedIndex = -1;
-
- RemoveAt (IndexOf (value));
+ int index = IndexOf (value);
+ if (index >= 0)
+ RemoveAt (index);
}
public void RemoveAt (int index)
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException ("index");
- if (index == owner.SelectedIndex)
+ if (index < owner.SelectedIndex)
+ --owner.SelectedIndex;
+ else if (index == owner.SelectedIndex)
owner.SelectedIndex = -1;
object removed = object_items [index];
return owner.Focused;
}
}
-
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing ) {
+ // Prevents corruption of combobox text by disposed object
+ owner.EnabledChanged -= OwnerEnabledChangedHandler;
+ owner.LostFocus -= OwnerLostFocusHandler;
+ }
+ base.Dispose(disposing);
+ }
+
internal override bool ActivateOnShow { get { return false; } }
}
vscrollbar_ctrl.Value = hli;
}
}
-
- Size = new Size (width, height);
- textarea_drawable = ClientRectangle;
- textarea_drawable.Width = width;
- textarea_drawable.Height = height;
-
+
+ var borderWidth = Hwnd.GetBorderWidth (CreateParams);
+ var borderAdjustment = dropdown_style == ComboBoxStyle.Simple ? new Size (0, 0) :
+ new Size (borderWidth.top + borderWidth.bottom, borderWidth.left + borderWidth.right);
+ Size = new Size (width, height + borderAdjustment.Height);
+ textarea_drawable = new Rectangle (ClientRectangle.Location,
+ new Size (width - borderAdjustment.Width, height));
+
if (vscrollbar_ctrl != null && show_scrollbar)
textarea_drawable.Width -= vscrollbar_ctrl.Width;
HighlightedIndex = owner.SelectedIndex;
CalcListBoxArea ();
+ // If the listbox would extend below the screen, move it above the textbox.
+ Rectangle scrn_rect = Screen.FromControl (owner).Bounds;
+ if (this.Location.Y + this.Height >= scrn_rect.Bottom)
+ this.Location = new Point (this.Location.X, this.Location.Y - (this.Height + owner.TextArea.Height));
Show ();
Refresh ();