teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/26 13:03

投稿

TN8001
TN8001

スコア10114

answer CHANGED
@@ -1,53 +1,52 @@
1
- まず参考コードがあるなら、質問に明記してください。
2
- [C# プロパティグリッド Enum型 以外でドロップダウンリストを表示](http://programmers.high-way.info/cs/property-grid-sort_dropdown.html)
3
-
4
-
5
- `UITypeEditor`を使うことが目的ではなく、入力欄で編集できないドロップダウンが目的でしょうか?
6
-
7
- であれば一番簡単なのは`enum`を使うことです。何もせずにその状態になります。
8
-
9
- それは嫌だという場合は↓の方法が手軽そうです。
10
-
11
- [.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)
12
-
13
-
14
- ```C#
15
- using System.ComponentModel;
16
- using System.Windows.Forms;
17
-
18
- namespace Questions316158
19
- {
20
- public partial class Form1 : Form
21
- {
22
- public Form1()
23
- {
24
- InitializeComponent();
25
-
26
- Controls.Add(new PropertyGrid
27
- {
28
- Dock = DockStyle.Fill,
29
- SelectedObject = new Item(),
30
- });
31
- }
32
- }
33
-
34
- public enum Group { 項目1, 項目2, 項目3, }
35
-
36
- public class Item
37
- {
38
- public Group GroupEnum { get; set; }
39
-
40
- [TypeConverter(typeof(GroupStringConverter))]
41
- public string GroupString { get; set; }
42
- }
43
-
44
- public class GroupStringConverter : StringConverter
45
- {
46
- public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
47
- public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
48
-
49
- public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
50
- => new StandardValuesCollection(new string[] { "項目1", "項目2", "項目3" });
51
- }
52
- }
1
+ まず参考コードがあるなら、質問に明記してください。
2
+ [C# プロパティグリッド Enum型 以外でドロップダウンリストを表示](http://programmers.high-way.info/cs/property-grid-sort_dropdown.html)
3
+
4
+
5
+ `UITypeEditor`を使うことが目的ではなく、入力欄で編集できないドロップダウンが目的でしょうか?
6
+
7
+ であれば一番簡単なのは`enum`を使うことです。何もせずにその状態になります。
8
+
9
+ それは嫌だという場合は↓の方法が手軽そうです。
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)
11
+
12
+
13
+ ```cs
14
+ using System.ComponentModel;
15
+ using System.Windows.Forms;
16
+
17
+ namespace Questions316158
18
+ {
19
+ public partial class Form1 : Form
20
+ {
21
+ public Form1()
22
+ {
23
+ InitializeComponent();
24
+
25
+ Controls.Add(new PropertyGrid
26
+ {
27
+ Dock = DockStyle.Fill,
28
+ SelectedObject = new Item(),
29
+ });
30
+ }
31
+ }
32
+
33
+ public enum Group { 項目1, 項目2, 項目3, }
34
+
35
+ public class Item
36
+ {
37
+ public Group GroupEnum { get; set; }
38
+
39
+ [TypeConverter(typeof(GroupStringConverter))]
40
+ public string GroupString { get; set; }
41
+ }
42
+
43
+ public class GroupStringConverter : StringConverter
44
+ {
45
+ public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
46
+ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
47
+
48
+ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
49
+ => new StandardValuesCollection(new string[] { "項目1", "項目2", "項目3" });
50
+ }
51
+ }
53
52
  ```