From 286f30d5cd76399333d660e7e064b8f67d0386e0 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 20 Apr 2022 22:22:17 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIComboBox:=20=E8=BF=87=E6=BB=A4=E6=96=87?= =?UTF-8?q?=E5=AD=97=E4=B8=BA=E7=A9=BA=E6=97=B6=EF=BC=8C=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=E6=98=BE=E7=A4=BA=E6=89=80=E6=9C=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIComboBox.cs | 41 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/SunnyUI/Controls/UIComboBox.cs b/SunnyUI/Controls/UIComboBox.cs index cda98d87..0174d256 100644 --- a/SunnyUI/Controls/UIComboBox.cs +++ b/SunnyUI/Controls/UIComboBox.cs @@ -26,6 +26,7 @@ * 2022-04-13: V3.1.3 根据Text自动选中SelectIndex * 2022-04-15: V3.1.3 增加过滤 * 2022-04-16: V3.1.3 过滤下拉控跟随主题配色 + * 2020-04-20: V3.1.5 过滤文字为空时,下拉框显示所有数据列表 ******************************************************************************/ using System; @@ -73,6 +74,9 @@ namespace Sunny.UI private void ShowDropDownFilter() { + if (Text.IsNullOrEmpty() && ShowFilter) + FillFilterTextEmpty(); + FilterItemForm.AutoClose = false; if (!FilterItemForm.Visible) { @@ -173,9 +177,9 @@ namespace Sunny.UI } } - [DefaultValue(false)] + [DefaultValue(100)] [Description("过滤显示最大条目数"), Category("SunnyUI")] - public int FilterMaxCount { get; set; } = 50; + public int FilterMaxCount { get; set; } = 100; protected override void DropDownStyleChanged() { @@ -189,6 +193,8 @@ namespace Sunny.UI private void SetDataConnection() { + if (!ShowFilter) return; + if (DropDownStyle == UIDropDownStyle.DropDown && DataSource != null && DisplayMember.IsValid()) { dataManager = (CurrencyManager)BindingContext[DataSource, new BindingMemberInfo(DisplayMember).BindingPath]; @@ -272,10 +278,10 @@ namespace Sunny.UI } filterForm.ListBox.Items.Clear(); + filterList.Clear(); + if (Text.IsValid()) { - filterList.Clear(); - if (DataSource == null) { foreach (var item in Items) @@ -309,12 +315,39 @@ namespace Sunny.UI } else { + FillFilterTextEmpty(); filterSelectedItem = null; filterSelectedValue = null; } } } + private void FillFilterTextEmpty() + { + if (DataSource == null) + { + foreach (var item in Items) + { + filterList.Add(item.ToString()); + } + } + else + { + if (dataManager != null) + { + for (int i = 0; i < Items.Count; i++) + { + filterList.Add(dataManager.List[i]); + } + } + } + + foreach (var item in filterList) + { + filterForm.ListBox.Items.Add(GetItemText(item)); + } + } + List filterList = new List(); private void ListBox_SelectedValueChanged(object sender, EventArgs e)