mooman_fl Posted March 27, 2003 Posted March 27, 2003 Ok... here is a new one concerning properties on a usercontrol. I would like to have the nifty nested properties on my control (i.e. Size, Location, DockPadding, etc.) Anyone have a clue as to how this is done? Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Heiko Posted March 28, 2003 Posted March 28, 2003 Just to make it clear to dumbos (as I am) ;) What do you mean with "nested"? Like "grouped" in the Properties view at designtime? Or "Hierarchical" at runtime as in myObject.Layout.Location = New System.Drawing.Point(42,42) ? Quote .nerd
mooman_fl Posted March 28, 2003 Author Posted March 28, 2003 I am talking like in the propertygrid at designtime. All the properties that contain a plus next to them. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 28, 2003 *Gurus* Posted March 28, 2003 I think you have to specify a TypeConverter attribute pointing to ExpandableObjectConverter on the class which your property has as its value. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 28, 2003 Author Posted March 28, 2003 I have read a few things that suggested this. However looking at the MSDN help, I am embarrassed to admit, helped very little. It was way over my head. Not to mention that everything I have seen on this is in VC++ (or maybe it was C#). Does anyone know of any information out there that takes this subject from the ground up geared towards a VB user? Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 28, 2003 *Gurus* Posted March 28, 2003 Here's a quick example I whipped up which does the trick: Imports System.ComponentModel Public Class ClassWithProperty Private _Expandy As ExpandyClass Public Sub New() _Expandy = New ExpandyClass() End Sub Public Property Expandy() As ExpandyClass Get Return _Expandy End Get Set(ByVal Value As ExpandyClass) _Expandy = Value End Set End Property End Class <TypeConverter(GetType(ExpandableObjectConverter))> _ Public Class ExpandyClass Private _Variable1, _Variable2 As Integer Public Property Variable1() As Integer Get Return _Variable1 End Get Set(ByVal Value As Integer) _Variable1 = Value End Set End Property Public Property Variable2() As Integer Get Return _Variable2 End Get Set(ByVal Value As Integer) _Variable2 = Value End Set End Property End Class Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 28, 2003 Author Posted March 28, 2003 LOL... your killing me man ;) You just whipped this up... *choke**gasp**goggle*:eek: Have you ever noticed how some people make seem so easy what makes the rest of us lose hair and sleep over? Thanks!!! I will examine this thoroughly. Once again you have saved the day. :) Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 28, 2003 *Gurus* Posted March 28, 2003 It's only easy because I had to do this before. Believe me, I had a similar headache then! Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 28, 2003 Author Posted March 28, 2003 Hmmm... tried implementing your method of doing this in my project. I got the expandable class made (Padding), I declared it in the declarations section, then in new tired to instantiate it. I got an error that says: Value of type 'ToolScroll.ToolPanel.Padding' cannot be converted to '1-dimensional array of ToolScroll.ToolPanel.Padding'. Any idea what this means and why I am getting it? I really haven't done anything different that I can see from your example. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 28, 2003 *Gurus* Posted March 28, 2003 You've put a () on your private declaration in the class I expect. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 28, 2003 Author Posted March 28, 2003 That seems to have indeed been the problem. I find it interesting that it is wrong to do it in your Private declaration, yet it is necessary and automatically added for you when you instantiate. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Heiko Posted March 28, 2003 Posted March 28, 2003 A declaration with () means that you are not declaring a single variable but an array. Instantiating with () means you are calling the parameterless constructor. These are two entirely different operations. Quote .nerd
mooman_fl Posted March 28, 2003 Author Posted March 28, 2003 Thanks Heiko, that makes sense. :) Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
dnagroove Posted March 30, 2003 Posted March 30, 2003 Divil, I would like to thank you too. This example has actually saved me various forms of headaches. Thanks again. Quote
wyrd Posted March 30, 2003 Posted March 30, 2003 I was passing by and figured I'd take a look at this interesting topic to see how it was done... I understand the example, and find it interesting actually, heh. Except, well, I got a n00b question.. Why is <TypeConverter(GetType(ExpandableObjectConverter))> needed? Quote Gamer extraordinaire. Programmer wannabe.
*Experts* Volte Posted March 30, 2003 *Experts* Posted March 30, 2003 The TypeConverterAttribute (attributes being the < > tags that precede some classes) tells VB what TypeConverter to use in the designer. In this case, it converts it to a format that the property window knows how to interpret and respond to accordingly. You could write your own TypeConverter as well, if you wanted. Quote
mooman_fl Posted March 30, 2003 Author Posted March 30, 2003 Hmmm... I would be interested in seeing how that is done if anyone cares to show an example. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 30, 2003 *Gurus* Posted March 30, 2003 TypeConverters are classes applied to other classes that enable conversion to and from that class type. A Size structure, for example, has a typeconverter that allows you to enter "100, 200" as a string in the propertygrid and it'll convert it to a size with X being 100 and Y being 200. The ExpandableObjectConverter class is extremely simple and does little more than tell the propertygrid that this object has properties that should be delved in to. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
wyrd Posted March 30, 2003 Posted March 30, 2003 Ahhh. Good stuff. I think it's time for me to do some reading up on Attributes and Reflection. :) Quote Gamer extraordinaire. Programmer wannabe.
Lexus Posted April 1, 2008 Posted April 1, 2008 This threat is very old, but, i have one little question about this. Is it possible to give the .ExpandyClass a name in the propertygrid? Now it displays Applicationname.ExpandyClass. I can't find this property? Giving Categories a name is not a problem, just the expanding item... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.