views:

418

answers:

2
+4  A: 

In the EditValue method, you are given a context. Use context.Instance to access the object that holds your property. This object should also contain a property that gives you access to the list of things you want to display. You could test if context.Instance is ITextureProvider for example, then cast it and access the textures. Not sure if this makes sense in your design but let me know.

Nicolas Cadilhac
My current design looks like this:MaterialDatabase: Holds a dictionary of Materials which contain the Texture2D classes.GeometryDatabase: Holds a dictionary of StaticGeometryChunks which contain the GeometryData.TileDatabase: Holds a dictionary of Tiles which contains a StaticGeometryChunk and a Material.When these classes are created they are passed a treeview to display what they have loaded, its a selection on the treeview that triggers the propertygrid to view the nodes tag (a reference to the dictionary object). I have a feeling this means the context will be the treeview?
Kath
Sorry my formatting has disappeared above and I ran out of characters. Thanks for the reply. The main overall class is the Tile, they use the other two objects (Materials/Geometry) for its data. This is so that if a user changes a texture in a material, all of the Tiles using that material get the change too.Could a slight redesign of this setup make my it easier?
Kath
context.Instance is the owner of the property. In your case, it would be Material. So, this Material class should be able to access the possible textures.
Nicolas Cadilhac
It works great now, thank you very much.
Kath
+1  A: 

As an alternative you can try the following approach. I find it very elegant, because it does not require to store a list of available property values in the object. Therefore, for example, you can show one set of values on one form and another set on another.

  1. Create an interface IYourDataProviderService.
  2. Create an implementation of IYourDataProviderService, which knows the concrete data to provide.
  3. Create a class implementing ISite. In GetService() method return an instance of class which implements IYourDataProviderService, if the serviceType parameter is typeof(IYourDataProviderService). I left rest of ISite methods throwing NotImplementedException (except DesignMode property) and for me it worked, but probably this is not an ideal solution.
  4. In 'Load' event handler assign your implementation to the Site property of your propertygrid.
  5. Enjoy!
ironic