//------------------------------------------------------------------------------------- void nativePopup_ItemSelected(SimSelectList sender, object sel) { nativePopup.ItemSelected -= new Pulsar.EventHandler<SimSelectList, object>(nativePopup_ItemSelected); SelectedItem = sel; OnUISelectedItemChanged(); }
//------------------------------------------------------------------------------------- /// <summary> /// Открывает выпадающий список. /// </summary> public void OpenDropDown() { try { if (OnDropDownOpening()) return; if (dropDown == null && (items == null || items.Count == 0)) return; if (dropDown == null) { IList list = null; if (sorted) { list = new List<object>(items.Cast<object>()); ((List<object>)list).Sort(Comparer); } else list = items; nativePopup = new SimSelectList(list); nativePopup.Opened += new EventHandler(DropDown_Opened); nativePopup.Closed += new ToolStripDropDownClosedEventHandler(DropDown_Closed); nativePopup.ItemSelected += new Pulsar.EventHandler<SimSelectList, object>(nativePopup_ItemSelected); nativePopup.SetAutoWidth(this.Width - 1); nativePopup.IsResizeble = isResizeble; nativePopup.SelectedItem = selectedItem; nativePopup.Show(this.PointToScreen(new Point(-1, this.Height - 1))); } else { dropDown.Opened += new EventHandler(DropDown_Opened); dropDown.Closed += new ToolStripDropDownClosedEventHandler(DropDown_Closed); if (dropDown is SimPopupControl) { ((SimPopupControl)dropDown).IsResizeble = isResizeble; ((SimPopupControl)dropDown).Show(this.PointToScreen(new Point(-1, this.Height - 1))); } else dropDown.Show(this.PointToScreen(new Point(-1, this.Height - 1))); } } catch (Exception Err) { Sim.Controls.ErrorBox.Show(Err); } }
//------------------------------------------------------------------------------------- #region << Methods >> private ToolStripDropDown GetEditor() { Type t = null; if(_binding.IsDefined) t = _binding.PropDescriptor.PropertyType; if(_pd != null) t = _pd.PropertyType; else t = _val == null ? typeof(string) : _val.GetType(); if(t == null) return null; if(InputFormat != TextBoxFormat.NotSet || t == typeof(string) || t == typeof(RefString)) { #region SimQuickEdit box = new SimQuickEdit(); box.Value = (Value ?? "").ToString(); box.Format = InputFormat; box.FormatExceptions = InputFormatExceptions; box.InputDone += (String_InputDone); if(box.Width < slValue.Width) box.Control.Width = slValue.Width - 10; return box; #endregion } if(t.IsPrimitive || t == typeof(decimal) || t == typeof(Money) || t == typeof(MoneyPrecise) || t == typeof(Amount) || t == typeof(UInt)) { #region SimQuickEdit box = new SimQuickEdit(); box.Value = (Value ?? "").ToString(); box.Format = TextBoxFormat.Digits; if(t == typeof(int) || t == typeof(long) || t == typeof(sbyte) || t == typeof(short) ) box.FormatExceptions += "-"; else if(t == typeof(decimal) || t == typeof(float) || t == typeof(double) || t == typeof(Money) || t == typeof(MoneyPrecise)) box.FormatExceptions += "-.,"; box.InputDone += (Number_InputDone); if(box.Width < slValue.Width) box.Control.Width = slValue.Width - 10; box.Tag = t; return box; #endregion } else if(t.IsEnum) { #region object val = Value; List<ComboBoxItem<Enum>> list = new List<ComboBoxItem<Enum>>(); SimSelectList box = new SimSelectList(list); foreach(Enum i in Enum.GetValues(t)) { var ci = new ComboBoxItem<Enum>(i, EnumTypeConverter.GetItemDisplayName(i)); list.Add(ci); if(i.Equals(val)) box.SelectedItem = ci; } box.ItemSelected += Enum_InputDone; box.SetAutoWidth(30); return box; #endregion } else if(_pd.PropertyType == typeof(DateTime) || _pd.PropertyType == typeof(DateTime?)) { #region object val = Value; SimDateSelect mc = new SimDateSelect(); if(val != null) mc.Value = (DateTime)val; mc.UIValueChanged += new Pulsar.EventHandler<object,DateTime>(DateTime_Closed); return mc; #endregion } return null; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //------------------------------------------------------------------------------------- #region << Constructors >> /// <summary> /// Конструктор по умолчанию. /// </summary> public SimComboBox() : base() { this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); sf.Alignment = StringAlignment.Near; sf.FormatFlags = StringFormatFlags.NoWrap; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; base.BackColor = SystemColors.Window; base.Height = PreferredHeight; base.Width = 120; nativePopup = new SimSelectList(items); }
void Enum_InputDone(SimSelectList sender, object val) { sender.ItemSelected -= Enum_InputDone; object oldval = Value; if(Object.Equals(oldval, val) == false) Value = ((IComboBoxItem)val).Key; }