Question about Windows Control Libraries and Properties
-
Hi, I am a newbie in C# and I was asked to develop a Windows Control Library. I have understood how to generate one and link it into a Windows Application Test Application. I want to make a property that shows up in the Property window and allows the user to have a pulldown to select the property, does anyone have a tutorial or some sample code to how this is done. I cant find anything online. Any help would be greatly appreciated Thanks
-
Hi, I am a newbie in C# and I was asked to develop a Windows Control Library. I have understood how to generate one and link it into a Windows Application Test Application. I want to make a property that shows up in the Property window and allows the user to have a pulldown to select the property, does anyone have a tutorial or some sample code to how this is done. I cant find anything online. Any help would be greatly appreciated Thanks
godspeed123 wrote:
to have a pulldown to select the property
Depends. If it's just an enum you can just expose a public property of that type and the PropertyGrid will display a combobox. Otherwise you need a type converter.
godspeed123 wrote:
anyone have a tutorial
They hide those in the documentation[^]
-
godspeed123 wrote:
to have a pulldown to select the property
Depends. If it's just an enum you can just expose a public property of that type and the PropertyGrid will display a combobox. Otherwise you need a type converter.
godspeed123 wrote:
anyone have a tutorial
They hide those in the documentation[^]
I actually have to read the DAQ Board and retrieve its properties and then want to allow the user to select from it. So for 1 property I will check the computer for the number of DAQ Boards and allow the user to select the DAQ Board of interest with the serial number. Do I have to use this type converter. Any example?
-
I actually have to read the DAQ Board and retrieve its properties and then want to allow the user to select from it. So for 1 property I will check the computer for the number of DAQ Boards and allow the user to select the DAQ Board of interest with the serial number. Do I have to use this type converter. Any example?
-
Thanks for the help, I have linked it all up and it works!! One more question is if I have an array with serial numbers in the Windows Control Library class, how do I send it over to the StringConverter class. So in:
public class UserControl1 : System.Windows.Forms.UserControl { ... public string daqSerial = new string[10]; private string testProperty; ... public void RetrieveSerials() { ... // find all the serials connected to comp } [DescriptionAttribute("Serial"), CategoryAttribute("Global Settings"), TypeConverter(typeof(testingPropertyConverter))] public string TestProp { get { return testProperty; } set { testProperty = value; } } } public class testingPropertyConverter : StringConverter { public override bool GetStandardValuesSupported( ITypeDescriptorContext context ) { return true; } public override StandardValuesCollection GetStandardValues( ITypeDescriptorContext context ) { return new StandardValuesCollection(new string[]{"test0", "test1", "test2"}); } }
So instead of putting those fixed values how do I show the daqSerial Array. Any help would be greatly appreciated -
Thanks for the help, I have linked it all up and it works!! One more question is if I have an array with serial numbers in the Windows Control Library class, how do I send it over to the StringConverter class. So in:
public class UserControl1 : System.Windows.Forms.UserControl { ... public string daqSerial = new string[10]; private string testProperty; ... public void RetrieveSerials() { ... // find all the serials connected to comp } [DescriptionAttribute("Serial"), CategoryAttribute("Global Settings"), TypeConverter(typeof(testingPropertyConverter))] public string TestProp { get { return testProperty; } set { testProperty = value; } } } public class testingPropertyConverter : StringConverter { public override bool GetStandardValuesSupported( ITypeDescriptorContext context ) { return true; } public override StandardValuesCollection GetStandardValues( ITypeDescriptorContext context ) { return new StandardValuesCollection(new string[]{"test0", "test1", "test2"}); } }
So instead of putting those fixed values how do I show the daqSerial Array. Any help would be greatly appreciatedHi, most of the TypeConverter methods receive a context in argument. You can use the Instance property in this context to retrieve your target instance and request from it some informations like your array.
Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker
-
Hi, most of the TypeConverter methods receive a context in argument. You can use the Instance property in this context to retrieve your target instance and request from it some informations like your array.
Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker
Thanks for the response, so how does this work? The function that I am using has the following prototype
public override StandardValuesCollection GetStandardValues( ITypeDescriptorContext context ) { // daq is the array of string in the Usercontrol class return new StandardValuesCollection( ((UserControl1) context.Instance).daq ); }
This code crashes, so I am clearly doing it wrong. Whats the correct method. Thanks for all the help -
Thanks for the response, so how does this work? The function that I am using has the following prototype
public override StandardValuesCollection GetStandardValues( ITypeDescriptorContext context ) { // daq is the array of string in the Usercontrol class return new StandardValuesCollection( ((UserControl1) context.Instance).daq ); }
This code crashes, so I am clearly doing it wrong. Whats the correct method. Thanks for all the helpYour code seems correct (but I don't see it in its whole), so I can't say where your error is...
Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker
-
Your code seems correct (but I don't see it in its whole), so I can't say where your error is...
Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker
the error I get is as follows: The following exception has occurred: InvalidCastException: Specified cast is not valid. Does that help? If not I can put up all the code
-
the error I get is as follows: The following exception has occurred: InvalidCastException: Specified cast is not valid. Does that help? If not I can put up all the code
So it means the target instance is not from the type you think it is. In debug mode you could confirm. If you are lost, you could send me a small sample (complete solution, no binaries in the zip file please) to reproduce your issue and I will quickly check. Please use my helpdesk at http://www.visualhint.com/index.php/support/submitrequest/
Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker