WinForms PropertyGrid 中的对象引用
假设我有一个名为 StaffMember
的类,它有一个 Position
类型的成员变量。
如果我有一个定义所有可能职位的枚举,那么当我将 StaffMember 对象加载到我的 PropertyGrid
中时,我可以看到一个下拉框,允许我从枚举中定义的职位中进行选择。
但是,我不知道所有不同类型的位置 - 它们可能每周都会发生变化 - 甚至在运行时也会发生变化。
所以我没有带有位置的静态枚举:相反,我有一个 List
,其中包含可以添加、更改等的当前列表。
当我将 StaffMember 对象与将变量列表到 PropertyGrid 中,位置变量被禁用,我无法设置/修改它。
是否有可能让它发挥作用,或者我正在做一些根本错误/不可能的事情?
Say I have a class called StaffMember
and it has a member variable of type Position
.
If I have an enum which defines all possible positions, then when I load the StaffMember object into my PropertyGrid
, I can see a drop-down box allowing me to select from the positions defined in my enum.
However, I do not know all the different types of positions - and they can change from week to week - or even at runtime for that matter.
So I don't have a static enum with positions: instead I have a List<Position>
which contains the current list which can be added to, changed, etc.
When I put my StaffMember object with a List variable into the PropertyGrid, the Position variable is disabled and I am unable to set/modify it.
Is it possible to get this to work, or am I doing something fundamentally wrong/impossible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您想要一个 UI 类型编辑器...
看看这个:
http: //msdn.microsoft.com/en-us/library/ms171840.aspx
Looks like you want an UI Type Editor ...
have a look at this:
http://msdn.microsoft.com/en-us/library/ms171840.aspx