By Greg McGuffey - 7/9/2008
I have a control that includes a property that is an object that has two properties within it, a string and an integer. I'd like this property to be an expandable property at design time in the property grid (like font, location, margins, ect are). I've figured out that I need a TypeConverter for the object and have built that. I figure out that I need to either override the GetPropertiesSupported and GetProperties methods or inherit from ExpandableObjectConverter (I've tried both) to get the parent object to expand into properties.
The problem is that when that property is Nothing (null), I can't expand it. Once I put in some appropriate text, then the plus sign shows up and the object's properties are expandable and shown. It is very likely something stupid, but how do I get the property to be expandable when the property is Nothing (null)?
Thanks!
|
By Trent L. Taylor - 7/10/2008
You can take the Null value into account within the TypeConverter and "pretend" it has a value. Another option is to initialize the value to a blank or empty value, which is generally what is done most of the time.The first place I would look would be the CanConvertFrom method and see if it is getting fired when Nothing (null) is being passed over...I would expect that it does. If so, then you can take matters into you own hands and supply a value which should allow the designer to expand.
|
By Greg McGuffey - 7/10/2008
This is getting very frustrating. I sort of got it working, but not in an acceptable manner. I the control, I added some code that would return a newly initialized object if in designmode and if the object was Nothing(null). This solution would mean that I'd have to remember to add that code any place I use this object...not good.
I'm starting to think this might have something to do with serialization. What do I need to do to make this property serialize correctly? Currently it is doing this...which isn't really working:
Me.dtvOutline.TopMostNode = CType(resources.GetObject("dtvOutline.TopMostNode"), FOXSystems.RAMS.UI.Forms.Controls.TopMostTreeNode)
What I'd expect is something more alone these lines:
Me.dtvOutline.TopMostNode.TopMostText = "(unassigned)"
Me.dtvOutline.TopMostNode.TopMostID = 0
The TopMostNode is of type TopMostTreeNode, which has been marked with the TypeConverter, Serializable and Browsable(True) attributes. What am I missing?
|
By Trent L. Taylor - 7/10/2008
Welcome to the world of frustrations Yeah, creating design-time implementations can make you cuss!One thing that you may be dealing with is the serialization as you mentioned. If you have a collection, then you will want to assign the Content tag through the DesignerSerializationVisibility property. Like this: Imports System.ComponentModel Public Class MyTest <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _ Public Property MyProperty() As MyCollection Get End Get Set(ByVal value As MyCollection) End Set End Property End Class
This might get you going in the right direction or at point you towards another attribute that would help. The above tag can be used to just ensure that the serialization is visible as well.
|
By Greg McGuffey - 7/10/2008
That did indeed help with serialization, but not much else. I'm attaching a small project with the basics. If you get a chance, could take a quick look and see if you can spot anything glaringly wrong? I have a feeling I "that close"
|
By Greg McGuffey - 7/14/2008
I know y'all are busy, but if anyone gets chance, I've love some feedback/correction about what I'm doing wrong with this type converter.
|
By Trent L. Taylor - 7/15/2008
Sorry, Greg. We have just been swamped lately. We are in class this week (and actually next as well). So things should return to normal the last week of the month...but I will really try to look at this one night.
|
By Greg McGuffey - 7/15/2008
Totally understand. Hope training is going well (I'm sure it is). I wish I was there. I'm going to try for the next one. Thanks for any time you can spare to take a quick look.
|
By Trent L. Taylor - 7/22/2008
OK....sorry for the REALLY long delay on this one. But I have changed your code to work more in line with what I would do. You will always want to have an instance of the object of some sort. Instead of testing on Nothing, just test on a -1 for the ID or something along those lines. You can also add a method on your TopMostNode item that tells if you it is in a default state to make this easier instead of writing the same thing over and over again (I did not write that method, but you get my point).
|
By Greg McGuffey - 7/22/2008
No problem on the delay. Thanks I'll take a look at it! This is much appreciated. You guys rock!
|
By Greg McGuffey - 8/15/2008
I had a chance (finally) to look at this. I got it working quite easily using your changes as a guide!
I see now that I needed to always have an instance of the property object (the TopMostNode), rather than using Nothing. Thanks again for the top notch support (above and beyond...).
|
By Trent L. Taylor - 8/18/2008
Cool...glad it worked out for you!
|