PropertyGrid 如何添加可编辑列表?
我有一个具有 IList 属性的类 MyClassA。我正在使用 PropertyGrid 控件来显示 MyClassA 的所有属性,并且我希望通过 MyClassA 的 PropertyGrid 显示和编辑 MyClassB 的列表。
目前,除了 MyClassB 列表的属性之外,所有其他属性都显示在属性网格中。如何将 MyClassB 列表添加到属性网格,用户可以在其中添加/编辑/删除列表中的项目?
尽管我仍在挖掘,但到目前为止,我还没有真正找到任何详细说明这一点的示例。
I have a class MyClassA that has an IList property. I am using a PropertyGrid control to display all the properties of MyClassA and I would like the list of MyClassB to be displayed and editable via the PropertyGrid for MyClassA.
I currently have all the other properties being displayed in the Property grid except for the property that is the list of MyClassB. How do I go about adding the List of MyClassB to the property grid where the user can add/edit/remove items from the List?
I haven't really been able to find any examples that go into detail on this as of yet although I am still digging.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我到目前为止已经制定出的解决方案,尽管它仍然不能 100% 符合我正在寻找的内容。
我发现可以根据自己的喜好修改此参考: http://www.codeproject.com/KB /tabs/customizingcollectiondata.aspx
我所做的是创建一个继承自 CollectionBase 并使用 ICustomTypeDescriptor 的新类。
完成此操作并实现基本功能后,我必须为该类创建一个 PropertyDescriptor。
代码如下:
Intersection 现在包含 ZoneCollection 而不是 IList,我现在可以编辑/添加/删除集合中包含的区域。
现在,如果我能让这个更通用,我会相对高兴。我的模型的另一个障碍是我必须使用它而不是 IList 从 Collection 基继承。这完全破坏了我对 NHibernate 类的映射,我现在必须尝试找出如何使用上述方法重新映射此列表。
如果有人想进一步详细说明这一点,我将不胜感激更多的见解。
Here is a solution I have worked out so far, although it still doesn't fit in 100% to what I am looking for.
I found this reference to modify for my liking: http://www.codeproject.com/KB/tabs/customizingcollectiondata.aspx
What I did was create a new class that inherits from CollectionBase and that uses an ICustomTypeDescriptor.
After I did this and implemented the basic functionality, I had to create a PropertyDescriptor for the class.
Here is the code:
Intersection now contains a ZoneCollection instead of an IList and I can now edit/add/remove the zones contained within the collection.
Now, if I could make this more generic I'd be relatively happy. Another hindrance for my model is that I had to inherit from Collection base using this, instead of IList. This completely broke my mapping of my class for NHibernate and I'm now having to try and figure out how to remap this list using the method mentioned above.
If anyone wants to elaborate this any further I'd greatly appreciate some more insight.
我知道这个主题已有 2 年多了,但也许您可能会感兴趣。
我有一个类似的问题。
首先:我需要 3D 空间中的一个点,该点应该可以在属性网格中进行配置
为此我创建了一个 Koord 类。为了使其在 PropertyGrid 中可更改,我创建了一个新类“KoordConverter : TypeConverter”
这是在 Vexel 中使用的(查看维基百科以了解它的用途:-))
为了创建 TestBock(某些 3D 对象),我使用了 Vexels 列表。
不幸的是,我的程序中需要一个测试块列表,可以通过属性网格看到。
从最上面开始:
BlockProperties 类包括 TestBocks 列表,我填充了一些内容以向您展示里面的内容。
接下来是我的 TestBlock 类,它非常简单
在 Vexels 中是我的程序所需的大部分魔力:
我什至在这里放置了一个 ToString() 以方便调试。
到目前为止,PropertyGrid 一切正常,但我无法编辑 Koords。
该类非常简单,但在 PropertyGrid 中不可编辑。
添加 TypeConverterClass 解决了这个问题(您可以在 Koord 代码下面找到 TypeConverter)
Typeconverter 是编写最复杂的代码。您可以在下面找到它:
基本上在所有这些设置完成之后,修改任何对象列表(测试块或每个测试块中的像素)都没有问题
希望如果有人跨过这个线程,这会对他们有所帮助。
最好的问候
Robin Blood
PS:在 PropertyGrid 中编辑没有问题,也许你只是没有正确理解你的构造函数!?
https://i.sstatic.net/LD3zf.png
I know this Topic is more than 2 years old, but maybe this could be interesting for you.
I had a similar Problem.
Starting with: I need a Point in 3D-Space which should be configurable in Property-Grid
For this I created a Class Koord. To make it changeable in PropertyGrid, I created a new Class "KoordConverter : TypeConverter"
This is used in a Vexel (check Wikipedia to find out what it's for :-) )
To create an TestBock (some 3D-Object) I'm using a List of Vexels.
Unfortunately I need a List of TestBlocks in my Program, Visible through the Property-Grid.
To start Topmost:
The Class BlockProperties includes the List of TestBocks which I filled a bit to show you what's inside.
Next is my TestBlock class, which is simply straight forward
In the Vexels is most of the magic I need for my Program:
I even put a ToString() here to make it easy during debugging.
So far everything worked fine for the PropertyGrid, but I could not edit the Koords.
The Class was pretty simple but not editable in the PropertyGrid.
Adding a TypeConverterClass solved this Problem (you can find the TypeConverter below the code of the Koord)
The Typeconverter was the most complicated code to write. You can find it below:
Basically after all of this was set up, It was no ploblem to modify any List of objects (TestBlocks or the Vexels within each TestBlock)
Hope it helps someone if they step over this Thread.
Best Regards
Robin Blood
PS:Editing is no problem in the PropertyGrid, maybe you just didn't get your constructors right !?
https://i.sstatic.net/LD3zf.png