如何创建公共字符串属性与下拉列表的选项? [英] How to create Public String property with drop-down list of options?

查看:162
本文介绍了如何创建公共字符串属性与下拉列表的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将字符串列表附加到String属性,以便用户可以从属性窗口中选择一个字符串?我应该实现ICollection或类别的东西吗?

Is it possible to attach a List of strings to a String property so that the user can select one of the strings from the Properties window? Should I implement ICollection or something of that sort?

推荐答案

如果你试图限制属性为几个特定选项,你应该使用一个枚举而不是字符串的属性。

If you are trying to restrict a property to one of a few specific options, you should use an Enum instead of a String for the property.

如果你想提供默认值,但让他们输入任何字符串并忽略默认值,然后你可以使用StringConverter。有关详细信息,请阅读充分利用.NET属性网格控件。它涵盖了这个确切的情况。

If you want to provide defaults, but let them type any string in and ignore the defaults, then you can use StringConverter. For details, read Getting the Most Out of the .NET Property Grid control. It covers this exact scenario.

这篇关于如何创建公共字符串属性与下拉列表的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆