locked
Make non-editable ComboBox in Powershell RRS feed

  • Question

  • So I'm writing a GUI that will interface with 3D printers.  I'm still fairly new to Powershell in general.

    Here is what I have in my code right now:

      # == Baudrate Combo Box == #
      $comboBox1 = New-Object System.Windows.Forms.ComboBox
      $comboBox1.Location = New-Object System.Drawing.Point(80, 55)
      $comboBox1.Size = New-Object System.Drawing.Size(98, 10)
      $comboBox1.Items.add("250000")
      $comboBox1.Items.add("115200")

    So the list is generated just fine, and my options appear and can be selected as they should be.  The only thing that doesn't work right, is that the ComboBox text area is editable.  The edited text never passes, which is good, but I want that box to be purely read/select only.

    I've seen some very generic statements all over the place, but none of them work, or are based in a different programming language like C#.

    I've tried adding the following, with no luck:

      $comboBox1.DropDownStyle = ComboBoxStyle.DropDownList

    Running with this line inserted gives me this:

    ComboBoxStyle.DropDownList : The term 'ComboBoxStyle.DropDownList' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\chevy\Desktop\GUI PROGRAM\TESTING.ps1:216 char:30
    +   $comboBox1.DropDownStyle = ComboBoxStyle.DropDownList
    +                              ~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (ComboBoxStyle.DropDownList:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    I've been at this for a couple days now, and I have yet to find a way to make the combo box read only.

    Thursday, June 4, 2020 2:36 AM

Answers

  • Hi,

    I saw the  code : $ComboBox.DropDownStyle = ComboBoxStyle.DropDownList.

    And the error message is:

    The term 'ComboBoxStyle.DropDownList' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


    In order for Powershell to recognize it, maybe you can use this:

    $ComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList;

    Please let us know if you would like further assistance.

    Best wishes,

    Young Yang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by Noah G Thursday, June 4, 2020 3:44 PM
    Thursday, June 4, 2020 7:41 AM

All replies

  • Hi,

    I saw the  code : $ComboBox.DropDownStyle = ComboBoxStyle.DropDownList.

    And the error message is:

    The term 'ComboBoxStyle.DropDownList' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


    In order for Powershell to recognize it, maybe you can use this:

    $ComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList;

    Please let us know if you would like further assistance.

    Best wishes,

    Young Yang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by Noah G Thursday, June 4, 2020 3:44 PM
    Thursday, June 4, 2020 7:41 AM
  • Hi Noah G,
    Based on your description, it is mostly related to Powershell. So it is recommended to ask the questions in Powershell forum and you can get more professional answer.
    Thank you for your understanding.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 4, 2020 7:41 AM
  • Add the following:

    $comboBox1.DropDownStyle = 'DropDownList'

    You can also use a listbox,  For only two entries we would not use a list or combo.


    \_(ツ)_/

    Thursday, June 4, 2020 7:54 AM
  • Thank you!!!!  Yeah, that did it.  I'm making notes of various code formatting.  Thanks for the help.
    Thursday, June 4, 2020 3:46 PM
  • I didn't know there was one.  I'm still getting the layout of the site.  I'll post over there next time.  Thanks for the heads up.
    Thursday, June 4, 2020 3:47 PM