Make non-editable ComboBox in Powershell

Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,476 Reputation points Microsoft Vendor
2020-07-16T02:10:40.3+00:00

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:
12631-snipaste-2020-07-16-10-28-12.png

https://social.technet.microsoft.com/Forums/windowsserver/en-US/7348778d-39f3-44c4-bdab-f5496d4250b2/make-noneditable-combobox-in-powershell?forum=winserverpowershell

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,354 questions
0 comments No comments
{count} votes

Accepted answer
  1. 2020-07-16T06:01:20.97+00:00

    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

    0 comments No comments

0 additional answers

Sort by: Most helpful