NewLife/XCoder

修正Combox控件的持久化;
大石头 authored at 2021-12-11 11:15:58
8310440
Tree
1 Parent(s) b5f3d5a
Summary: 1 changed files with 13 additions and 2 deletions.
Modified +13 -2
Modified +13 -2
diff --git a/XCoder/Common/ControlConfig.cs b/XCoder/Common/ControlConfig.cs
index ce41cc7..69b6238 100644
--- a/XCoder/Common/ControlConfig.cs
+++ b/XCoder/Common/ControlConfig.cs
@@ -4,6 +4,7 @@ using System.IO;
 using System.Linq;
 using System.Windows.Forms;
 using NewLife;
+using NewLife.Reflection;
 using NewLife.Serialization;
 
 namespace XCoder.Common
@@ -52,7 +53,12 @@ namespace XCoder.Common
                         if (dic.TryGetValue(item.Name, out v))
                         {
                             if (cbox.DropDownStyle == ComboBoxStyle.DropDownList)
-                                cbox.SelectedValue = v;
+                            {
+                                if (cbox.Items.Count > 0 && cbox.Items[0].GetType().GetTypeCode() == TypeCode.Object)
+                                    cbox.SelectedValue = v;
+                                else
+                                    cbox.SelectedItem = v;
+                            }
                             else
                                 cbox.DataSource = (v + "").Split(",");
                         }
@@ -88,7 +94,12 @@ namespace XCoder.Common
                     case NumericUpDown nud: dic[item.Name] = nud.Value; break;
                     case ComboBox cbox:
                         if (cbox.DropDownStyle == ComboBoxStyle.DropDownList)
-                            dic[item.Name] = cbox.SelectedValue;
+                        {
+                            if (cbox.SelectedValue != null)
+                                dic[item.Name] = cbox.SelectedValue;
+                            else
+                                dic[item.Name] = cbox.SelectedItem;
+                        }
                         else
                         {
                             var list = new List<String> { cbox.Text };