* UIComboBox: 过滤文字为空时,下拉框显示所有数据列表

This commit is contained in:
Sunny 2022-04-20 22:22:17 +08:00
parent ed53b4bd12
commit 286f30d5cd

View File

@ -26,6 +26,7 @@
* 2022-04-13: V3.1.3 Text自动选中SelectIndex * 2022-04-13: V3.1.3 Text自动选中SelectIndex
* 2022-04-15: V3.1.3 * 2022-04-15: V3.1.3
* 2022-04-16: V3.1.3 * 2022-04-16: V3.1.3
* 2020-04-20: V3.1.5
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -73,6 +74,9 @@ namespace Sunny.UI
private void ShowDropDownFilter() private void ShowDropDownFilter()
{ {
if (Text.IsNullOrEmpty() && ShowFilter)
FillFilterTextEmpty();
FilterItemForm.AutoClose = false; FilterItemForm.AutoClose = false;
if (!FilterItemForm.Visible) if (!FilterItemForm.Visible)
{ {
@ -173,9 +177,9 @@ namespace Sunny.UI
} }
} }
[DefaultValue(false)] [DefaultValue(100)]
[Description("过滤显示最大条目数"), Category("SunnyUI")] [Description("过滤显示最大条目数"), Category("SunnyUI")]
public int FilterMaxCount { get; set; } = 50; public int FilterMaxCount { get; set; } = 100;
protected override void DropDownStyleChanged() protected override void DropDownStyleChanged()
{ {
@ -189,6 +193,8 @@ namespace Sunny.UI
private void SetDataConnection() private void SetDataConnection()
{ {
if (!ShowFilter) return;
if (DropDownStyle == UIDropDownStyle.DropDown && DataSource != null && DisplayMember.IsValid()) if (DropDownStyle == UIDropDownStyle.DropDown && DataSource != null && DisplayMember.IsValid())
{ {
dataManager = (CurrencyManager)BindingContext[DataSource, new BindingMemberInfo(DisplayMember).BindingPath]; dataManager = (CurrencyManager)BindingContext[DataSource, new BindingMemberInfo(DisplayMember).BindingPath];
@ -272,10 +278,10 @@ namespace Sunny.UI
} }
filterForm.ListBox.Items.Clear(); filterForm.ListBox.Items.Clear();
filterList.Clear();
if (Text.IsValid()) if (Text.IsValid())
{ {
filterList.Clear();
if (DataSource == null) if (DataSource == null)
{ {
foreach (var item in Items) foreach (var item in Items)
@ -309,12 +315,39 @@ namespace Sunny.UI
} }
else else
{ {
FillFilterTextEmpty();
filterSelectedItem = null; filterSelectedItem = null;
filterSelectedValue = 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<object> filterList = new List<object>(); List<object> filterList = new List<object>();
private void ListBox_SelectedValueChanged(object sender, EventArgs e) private void ListBox_SelectedValueChanged(object sender, EventArgs e)