HOWTO avoid that the IDE place the propertys ordered alphabetically ?
Hello,
I'm a having a issue with my custom control, because the IDE place the attributes in alphabetical order in the code (when the user place the control in a form). e...g... : if you control have three properties (Buttons, Captions y ValuesToReturn), the IDE place the attributes in this order:
mycontrol.Buttons = 2;
mycontrol.Captions = "YN";
mycontrol.ValuesToReturn ="10";
I need that the properties become placed like this:
mycontrol.ValuesToReturn ="10";
mycontrol.Captions = "YN";
mycontrol.Buttons = 2;
I need that theValuesToReturn property become the first property that the IDE set, because its value is used by theButtons property (in this property is invoked a procedure that creates the buttons), but I don't know how to do it!. Looking for in the web, I found that I need to implement the ISupportInitialization interfase, but the problems persist yet!.
Please, help me!,
[956 byte] By [
CFQüeb] at [2007-12-16]
Hello Cavalli, Many thanks for your reply

. A
Custom Type Descriptor and the
override for the
Getproperties() method only works in the
PropertyGrid (I suppose) but I need that the properties order become applied
into the code (automatically generate for the
IDE), when the user place the control on the form. If you have a code for see an example... please share with me! 10x a lot!
If the current value of the property is the same with the defeault value, then it will not be included in the CodeStatementCollection, because the property will not be serialized. To ensure that your property's serialization, you can include a method that starts with ShouldSerialize and ends with the name of your property, that returns a boolean value, true mean to serialize, otherwise false.
public bool ShouldSerializeMyProperty
{
return true;
}
The code above forces your property to be included in CodeStatementCollection.
Here's a detailed article (with sample) on CodeDom serialization:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/custcodegen.asp
-chris