Getting Checkbox Values from a ListBox(New to ShowUI)

Mar 19, 2014 at 10:52 PM
I am trying to get the check box values from inside of a listbox. From the examples I have seen what I have here should be working but instead of getting a hash of the list box values I get a hash with one key - "Check" and the value of the last check box. What am I doing wrong here?
$ws = @{
    WindowStartupLocation = "CenterScreen"
    Width = 375
    Height = 305
}

$Test = Window @ws {
    StackPanel -Background Black{
        
        ListBox -Background Black `
         -ItemsSource (Get-ChildItem ${UPLOAD_DRIVE_LETTER}:\| ?{ $_.PSIsContainer }) `
         -ItemTemplate {
            New-StackPanel -Orientation Horizontal -Children {
                CheckBox -Margin 5 `
                    -Name Check `
                    -Foreground White
            } | ConvertTo-DataTemplate -Binding @{
                "Check.Content" = $_.Name       
                }
        }
        Button "Build" -Margin 2 -On_Click{    
           Set-UIValue -UI $window -PassThru | Close-Control  
        }
} 
}-Show
Coordinator
Mar 20, 2014 at 3:44 AM
The ListBox default behavior is to return the selected object.
The CheckBox behavior is to return a hashtable of the NAME and whether it's checked or not. You named all of yours "Check" ...

Personally, I'd just set ListBox -SelectionMode Multiple and leave the checkboxes out of it:
$ws = @{
    WindowStartupLocation = "CenterScreen"
    Width = 375
    Height = 305
}

$Path = "${UPLOAD_DRIVE_LETTER}:\"


$Test = Window @ws {
    StackPanel -Background Black {        
        ListBox -Name list -SelectionMode Multiple `
            -Background Transparent -Foreground White `
            -ItemsSource (Get-ChildItem $Path | ?{ $_.PSIsContainer })
        
        Button "Build" -Margin 2 -On_Click { Close-Control $Window }
    } 
} -On_Closing { Set-UIValue $Window (Get-UIValue $list)  } -Show
I like to Set-UIValue in the Closing event of the window, because that way it works even if they don't use the button ...

Getting a "CheckListBox" working would require weird databinding, I'll think about that
Marked as answer by DiscipleofHoid on 3/20/2014 at 7:09 AM
Mar 20, 2014 at 2:09 PM
The Select Multiple will work great.

With the check boxes I could see that all of the boxes were being named Check - I just couldn't figure out how to bind the data to give them different names.

This seems to simplify the problem a lot which sounds great to me.

Thanks for your help.