回答編集履歴

1

見直しキャンペーン中

2023/07/26 13:03

投稿

TN8001
TN8001

スコア9330

test CHANGED
@@ -1,105 +1,52 @@
1
1
  まず参考コードがあるなら、質問に明記してください。
2
-
3
2
  [C# プロパティグリッド Enum型 以外でドロップダウンリストを表示](http://programmers.high-way.info/cs/property-grid-sort_dropdown.html)
4
-
5
-
6
-
7
3
 
8
4
 
9
5
  `UITypeEditor`を使うことが目的ではなく、入力欄で編集できないドロップダウンが目的でしょうか?
10
6
 
11
-
12
-
13
7
  であれば一番簡単なのは`enum`を使うことです。何もせずにその状態になります。
14
8
 
15
-
16
-
17
9
  それは嫌だという場合は↓の方法が手軽そうです。
18
-
19
-
20
-
21
10
  [.NET Framework の PropertyGrid コントロールの高度な活用 - 簡単なドロップダウン プロパティのサポートを提供するには | Microsoft Docs](https://docs.microsoft.com/ja-jp/previous-versions/msdn/architecture-center/cc440113(v=vs.71)#%E7%B0%A1%E5%8D%98%E3%81%AA%E3%83%89%E3%83%AD%E3%83%83%E3%83%97%E3%83%80%E3%82%A6%E3%83%B3-%E3%83%97%E3%83%AD%E3%83%91%E3%83%86%E3%82%A3%E3%81%AE%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88%E3%82%92%E6%8F%90%E4%BE%9B%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF)
22
11
 
23
12
 
24
-
25
-
26
-
27
- ```C#
13
+ ```cs
28
-
29
14
  using System.ComponentModel;
30
-
31
15
  using System.Windows.Forms;
32
16
 
33
-
34
-
35
17
  namespace Questions316158
36
-
37
18
  {
38
-
39
19
  public partial class Form1 : Form
40
-
41
20
  {
42
-
43
21
  public Form1()
44
-
45
22
  {
46
-
47
23
  InitializeComponent();
48
24
 
49
-
50
-
51
25
  Controls.Add(new PropertyGrid
52
-
53
26
  {
54
-
55
27
  Dock = DockStyle.Fill,
56
-
57
28
  SelectedObject = new Item(),
58
-
59
29
  });
60
-
61
30
  }
62
-
63
31
  }
64
-
65
-
66
32
 
67
33
  public enum Group { 項目1, 項目2, 項目3, }
68
34
 
69
-
70
-
71
35
  public class Item
72
-
73
36
  {
74
-
75
37
  public Group GroupEnum { get; set; }
76
38
 
77
-
78
-
79
39
  [TypeConverter(typeof(GroupStringConverter))]
80
-
81
40
  public string GroupString { get; set; }
82
-
83
41
  }
84
42
 
85
-
86
-
87
43
  public class GroupStringConverter : StringConverter
88
-
89
44
  {
90
-
91
45
  public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
92
-
93
46
  public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
94
47
 
95
-
96
-
97
48
  public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
98
-
99
49
  => new StandardValuesCollection(new string[] { "項目1", "項目2", "項目3" });
100
-
101
50
  }
102
-
103
51
  }
104
-
105
52
  ```