Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Question about Windows Control Libraries and Properties

Question about Windows Control Libraries and Properties

Scheduled Pinned Locked Moved C#
tutorialcsharphelpquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    godspeed123
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • G godspeed123

      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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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[^]

      G 1 Reply Last reply
      0
      • L led mike

        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[^]

        G Offline
        G Offline
        godspeed123
        wrote on last edited by
        #3

        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?

        L 1 Reply Last reply
        0
        • G godspeed123

          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?

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          godspeed123 wrote:

          Any example?

          yes, the link in my previous post

          G 1 Reply Last reply
          0
          • L led mike

            godspeed123 wrote:

            Any example?

            yes, the link in my previous post

            G Offline
            G Offline
            godspeed123
            wrote on last edited by
            #5

            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

            V 1 Reply Last reply
            0
            • G godspeed123

              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

              V Offline
              V Offline
              visualhint
              wrote on last edited by
              #6

              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

              G 1 Reply Last reply
              0
              • V visualhint

                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

                G Offline
                G Offline
                godspeed123
                wrote on last edited by
                #7

                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

                V 1 Reply Last reply
                0
                • G godspeed123

                  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

                  V Offline
                  V Offline
                  visualhint
                  wrote on last edited by
                  #8

                  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

                  G 1 Reply Last reply
                  0
                  • V visualhint

                    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

                    G Offline
                    G Offline
                    godspeed123
                    wrote on last edited by
                    #9

                    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

                    V 1 Reply Last reply
                    0
                    • G godspeed123

                      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

                      V Offline
                      V Offline
                      visualhint
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups