Okay, so I have a class which has a member property Points, which is a list of points (List<Point>). I'm trying to display this class in a PropertyGrid at runtime. That works and I can open up the Collections editor for Points and it shows me all the points that are currently in the list. However, under the right side of the collections editor, the X and Y value for each Point is just "Object does not match target type" and I can't actually change it. I can add a new point to the List from there, but it's just 0,0 and I can't change it.
If I use an array of Points instead of a List, I can expand the array in the PropertryGrid and edit X/Y values of each point, however if I try to bring up the Collections editor on the array I get the same issue as above, with me being unable to edit the points.
I'm thoroughly baffled. Everything I've found on google with people encountering this error message is vastly different situations that don't help me, or they're using a collection containing multiple types of objects in it, which is not the case for me since I'm using a strongly typed list of Points which isn't even a custom class.
At this point I'm probably just going to ignore it since using the array sort of works, but it's frustrating.
Posts
I've never actually used PropertyGrid before, but I'm very familiar with many of the idiosyncrasies in .NET... if I saw some code, hopefully I could be of assistance.
I'm at work now so don't have the code with me, but it's fairly trivial.
Then in my form, I have a PropertyGrid. It handles the filling automatically by just setting the SelectedObject property. There's some code in a mouseup event handler to select my object from the form which works and I get back the correct object. So the code to actually put it in the PropertyGrid is just
I can get some actual code snippets this evening, but this is the core of the problem.
I started a new project and limited it to just enough code to test. Below is the entirety of my code (aside from auto-generated Form Designer code).
http://www.codeproject.com/KB/tabs/customizingcollectiondata.aspx
It sounds like, when you're dealing with collections (even generic, strongly-typed collections like the one you have), you may have to implement the ICustomTypeDescriptor interface and create a class that inherits from PropertyDescriptor so that the PropertyGrid knows how to deal with the collection of points and the point objects themselves.
Give this a shot, as well as AngelHedgie's suggestion... usually these kinds of problems either stem from not having the right attributes attached to the class, not implementing an expected interface, or both.
I'll read that article and see if it helps. Otherwise I guess I'll just implement my own point class since that seems to work even though the built in one doesn't. Odd though.