locked
Foreach undesired output RRS feed

  • Question

  • Team,

    I have a piece of code that is generating an undesired console output. 

    $global contains the promotions imported from an XML file. 

    $comboPromos = New-Object system.windows.Forms.ComboBox
    $comboPromos.Text = "Choose Promo"
    $comboPromos.Width = 300
    $comboPromos.Height = 200
    $comboPromos.location = new-object system.drawing.point(65,400)
    $comboPromos.Font = "Microsoft Sans Serif,10"
    foreach ($promo in $global:PromoList.Promotions.Promo){
      $comboPromos.items.Add($promo.Name)
      }
    $HWHRFourWindsDataManager.controls.Add($comboPromos)

    This is the console output I get. 

    0
    1
    2
    3
    4
    5
    6

    Please help.

    Tuesday, January 16, 2018 4:55 PM

Answers

  • Or:

    foreach ($promo in $global:PromoList.Promotions.Promo){
         [void]$comboPromos.items.Add($promo.Name)
    }


    \_(ツ)_/

    • Marked as answer by AllenVh Tuesday, January 16, 2018 5:43 PM
    Tuesday, January 16, 2018 5:10 PM

All replies

  •  

    $comboPromos.DataSource = [collections.arraylist]$promoList.Promotions.Promo
    $comboPromos.DisplayName = 'Name'


    \_(ツ)_/


    • Edited by jrv Tuesday, January 16, 2018 5:09 PM
    Tuesday, January 16, 2018 5:09 PM
  • Or:

    foreach ($promo in $global:PromoList.Promotions.Promo){
         [void]$comboPromos.items.Add($promo.Name)
    }


    \_(ツ)_/

    • Marked as answer by AllenVh Tuesday, January 16, 2018 5:43 PM
    Tuesday, January 16, 2018 5:10 PM
  • Thanks this the [void] did it.
    Tuesday, January 16, 2018 5:44 PM