none
Powershell Forms - Textbox value does not refresh RRS feed

  • Question

  • I am trying to a script which pulls out public cloud VM names in the combobox. Once the VM name is selected, it would display the instance size in a text box which I am getting displayed on SelectedIndexChanged event of combobox. The script works fine and the value is displayed. However when I select a different VM, the event is triggered and I can see the changed value assigned to the text box however the value in GUI does not refresh. I have tried calling the , clear(), update(), refresh() methods of the textbox still no luck. Any idea on how to get it done?

    Here is the code. (SelectedIndexChanged Event)

    $awsModVMNameBox_OnSelect = 
    {
    $awsModSize = New-Object System.Windows.Forms.Label
    $awsModSize.Location = New-Object System.Drawing.Size(5,50) 
    $awsModSize.Size = New-Object System.Drawing.Size(100,11) 
    $awsModSize.Text = "VM Size"
    $script:awsModPage.controls.Add($awsModSize)

    $script:awsModSizeBox = New-Object System.Windows.Forms.TextBox
    $script:awsModSizeBox.Location = New-Object System.Drawing.Size(110,50) 
    $script:awsModSizeBox.Size = New-Object System.Drawing.Size(200,11)
        foreach($item in $script:arrObj) {
            if($item.Name -eq $awsModVMNameBox.Text){
                $script:InstanceSize = $item.InstanceType
            }
        }
        $script:awsModSizeBox.Clear()
        $script:awsModSizeBox.Text = $script:InstanceSize

    • Moved by Bill_Stewart Wednesday, September 4, 2019 7:53 PM Unanswerable drive-by question
    Friday, April 5, 2019 10:36 AM

All replies

  • Please post your code correctly using the code posting tool provided.

    You code does not make any sense.  Why are you recreating the textbox on every event? 

    Create you form and add the events.  Display the form.  Do not keep create controls in the vents.


    \_(ツ)_/

    Friday, April 5, 2019 12:29 PM
  • Thanks a ton. That did it. I removed the controls out of the event handler and it did the trick. the value is getting updated now. 
    Friday, April 5, 2019 12:34 PM