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

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

问题描述

是否有可能字符串列表连接成一个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天全站免登陆