question

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT asked ·

Make non-editable ComboBox in Powershell

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
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered ·

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

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.