From edfc0b1a05e34ab733cd936f6a17f17a1bdd6949 Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 24 May 2022 13:34:38 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIComboBox:=20Selceted=3D-1=EF=BC=8C?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIComboBox.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/SunnyUI/Controls/UIComboBox.cs b/SunnyUI/Controls/UIComboBox.cs index bf13589e..d0979ca9 100644 --- a/SunnyUI/Controls/UIComboBox.cs +++ b/SunnyUI/Controls/UIComboBox.cs @@ -26,8 +26,9 @@ * 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 过滤文字为空时,下拉框显示所有数据列表 - * 2020-05-04: V3.1.8 过滤时修复ValueMember绑定值的显示 + * 2022-04-20: V3.1.5 过滤文字为空时,下拉框显示所有数据列表 + * 2022-05-04: V3.1.8 过滤时修复ValueMember绑定值的显示 + * 2022-05-24: V3.1.9 Selceted=-1,清除文本 ******************************************************************************/ using System; @@ -410,10 +411,18 @@ namespace Sunny.UI private void Box_SelectedIndexChanged(object sender, EventArgs e) { SelectTextChange = true; - if (ListBox.SelectedItem != null && !ShowFilter) - Text = ListBox.GetItemText(ListBox.SelectedItem); + if (!ShowFilter) + { + if (ListBox.SelectedItem != null) + Text = ListBox.GetItemText(ListBox.SelectedItem); + else + Text = ""; + } + SelectTextChange = false; - SelectedIndexChanged?.Invoke(this, e); + + if (!Wana_1) + SelectedIndexChanged?.Invoke(this, e); } public event EventHandler SelectedIndexChanged; @@ -575,11 +584,20 @@ namespace Sunny.UI { if (!ShowFilter) { + if (DataSource != null && value == -1 && SelectedIndex > 0) + { + Wana_1 = true; + SelectedIndex = 0; + Wana_1 = false; + } + ListBox.SelectedIndex = value; } } } + private bool Wana_1; + [Browsable(false), Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description("选中项"), Category("SunnyUI")] public object SelectedItem