c# Winform PropertyGrid 实现下拉框 多选

c# Winform PropertyGrid 实现下拉框 多选

 1 using PropertyGridHelpers.Controls;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.ComponentModel;
 5 using System.Drawing.Design;
 6 using System.Windows.Forms;
 7 using System.Windows.Forms.Design;
 8 
 9 namespace PropertyGridHelpers.UIEditors
10 {
11 
12     public class FlagEnumUIEditor : UITypeEditor
13     {
14         private CheckedListBoxEx check;
15 
16         public FlagEnumUIEditor()
17         {
18             check = new CheckedListBoxEx();
19             check.BorderStyle = BorderStyle.None;
20         }
21 
22         public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
23         {
24             if (context != null && context.Instance != null && provider != null)
25             {
26                 IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
27                 if (service != null)
28                 {
29                     List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
30                     for (int i = 0; i < 100; i++)
31                     {
32                         list.Add(new KeyValuePair<string, string>(i.ToString(), Guid.NewGuid().ToString("N")));
33                     }
34                     check.DataSource = list;
35                     service.DropDownControl(check);
36                     return check.GetSelectItemValueText;
37                 }
38             }
39             return null;
40         }
41 
42         public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
43         {
44             return UITypeEditorEditStyle.DropDown;
45         }
46     }
47 }
FlagEnumUIEditor

相关文章:

  • 2021-04-08
  • 2021-08-23
  • 2021-08-27
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-06
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案