How to add data to a specific column on a ListBox

Welcome Forums General PowerShell Q&A How to add data to a specific column on a ListBox

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 months, 2 weeks ago.

  • Author
    Posts
  • #164409

    Participant
    Topics: 51
    Replies: 122
    Points: 78
    Rank: Member

    Hi!

    I'm trying to create my firsts PowerShell GUI scripts...
    I need to know how to add data to specific columns on a ListBox with MultiColumns property set.
    My code is this for now:

    $ListBox1 = New-Object System.Windows.Forms.ListBox
    $ListBox1.Location  = New-Object System.Drawing.Point(22,43)
    $ListBox1.Size = New-Object System.Drawing.Size(410,410)
    $ListBox1.AutoSize = $true
    $ListBox1.MultiColumn = $true
    $ListBox1.SelectionMode = "MultiExtended"
    $ListBox1.ColumnWidth = 250
    $Users = get-aduser -filter "name -like 'a*'" -Properties SamAccountName
    foreach ($User in $Users){
        $ListBox1.Items.Add($User.Name) | Out-Null
        
    }
    $form.Controls.Add($ListBox1)

    But it only adds data to the first column, and I wanted to add the SamAccountName to the second column.
    Something like this:
    Name / SamAccountName
    User Full Name / user.name
    Second User Full Name / seconduser.name

    Any ideas?

  • #164500

    Participant
    Topics: 2
    Replies: 999
    Points: 1,946
    Helping Hand
    Rank: Community Hero

    You cross posted this from multiple forum(s)/Q&A sites, that I responded to there.  So, take a look at that response.

  • #164509

    Participant
    Topics: 51
    Replies: 122
    Points: 78
    Rank: Member

    Hi,

    Sorry. I'll try to delete it. Thanks.

You must be logged in to reply to this topic.