Trouble with TypeConverter


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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!
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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?
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Welcome to the world of frustrations BigGrin  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.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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" BigGrin
Attachments
ExpandableTypeConverterTest.zip (151 views, 20.00 KB)
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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. Ermm
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Totally understand. Hope training is going well (I'm sure it is). I wish I was there. Ermm I'm going to try for the next one. Thanks for any time you can spare to take a quick look.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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).
Attachments
ExpandableTypeConverterTest.zip (163 views, 78.00 KB)
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
No problem on the delay. Thanks I'll take a look at it! This is much appreciated. You guys rock! BigGrin
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search