ComboBox Sorting is lost after Packaging as EXE

I have created a Powershell Forms application which has a ComboBox in it. When running the script through Visual Studio Code, the items are correctly sorted, but after packaging as an EXE, the sort order is lost.

I have tried:

  1. Using $ComboBox.Sorted = $True before or after adding the items to the ComboBox
  2. For ($i=0; $i -le $Array.Count; $i++) {$ComboBox.Items.Add($Array[$i])}
  3. For ($i=$Array.Count; $i -ge 0; $i–) {$ComboBox.Items.Add($Array[$i])}
  4. ForEach ($Item in $Array) {$ComboBox.Items.Add($Item)}
  5. $Array = Get-Something | Sort-Object Name
  6. $Array = Get-Something | Sort-Object Name -Descending

None of the above seems to have any effect on changing the order within the EXE even though you see the changes from within VS Code.

The kicker here though is that if compile the script as an EXE through PS2EXE, the sort order is correct.

I don’t know if this is a bug, or I simply need to change the way I am using the ComboBox? Any help would be greatly appreciated.

Hi @The_Owl , could you please post your code? I am not able to reproduce this issue. The sorting in combobox compiled to EXE via VS Code works as expected on my end.

Thanks DataTraveler, but I have just worked out what the issue was.

It wasn’t the ComboBox at all, it was actually the guy behind the keyboard…

My issue was that creating new scripts in the same folder as an exisiting ‘package.psd1’ doesn’t generate a new ‘package.psd1’ file based on the script name. Essentially, I was re-compiling a an old version of the script.

Sorry to waste your time there.

1 Like

Hi @The_Owl,

Thank you for following up on this. I don’t see this as a waste of time at all. You shared valuable insight here which is likely to help others in the future. That is exactly why these forums exist, I imagine. So thanks again!