Databinding when using two listviews

Aug 26, 2011 at 10:53 PM

I have a Grid wtih two columns.  Each column has a listview.  When I double click on a row of data in the listview in column #1 I call a function that populates a collection.  I want to display the data from that collection in the listview in column #2 - sort of a summary pane on the left and a detail pane on the right.  I can't get my data to show in the listview on the right (detail) pane.  I need help with the databinding.  Here is my code with most column names remvoed from the gridviews for simplicity. 

Thanks

Function Get-Detail($object)
{
     $key = $object  | select-object -expandproperty key
     $detaildata=import-csv \somedata.csv | where {$_.Key -eq $key}| sort -p count -descending
}

New-Window -Title "Windows Deployment Advisor" -WindowStartupLocation CenterScreen -Width 1200 -Height 900 -On_Loaded {
} {

    New-GRid -Rows 800,35 -columns 600,600* {
        New-ListView -Row 0 -column 0 -controlname "Summary" -DataBinding @{
            ItemsSource = New-Binding
        } -View {
            New-GridView -AllowsColumnReorder  -Columns {
                New-GridViewColumn "date" -width 110
            }
        } -DataContext {
                import-csv \somedata.csv | where {$_.date -gt " "}
        } -On_MouseDoubleClick {
               get-detail $this.selecteditems $window
        } #New-LIstView
           
        New-ListView -controlname "Detail" -Row 0 -Column 1 -dataBinding @{
            ItemSource = New-Binding 

        } -View {
            New-GridView -AllowsColumnReorder -Columns {
                New-GridViewColumn "delta"
            }
        }
        New-Button -Content "Okay" -Row 1 -Column 0 -width 115 -margin 5 -on_click { close-control}
    } #New-Grid
} -show

Developer
Aug 27, 2011 at 2:00 AM

Here is I worked up. I had to guess at the data so it may not be completely accurate.

Function Get-Detail($item, $window)
{
     $detailListView = $window | Get-ChildControl -ByName "Detail" 
     $key = $item  | select-object -expandproperty date     
     
     $data = import-csv .\somedata.csv | where {$_.date -eq $key} | sort -p count -descending
     $detailListView.DataContext = @($data)
}

New-Window -Title "Windows Deployment Advisor" -WindowStartupLocation CenterScreen -Width 1200 -Height 900 {

    New-Grid -Rows 800,35 -columns 600, 600* {
        New-ListView -Row 0 -column 0 -controlname "Summary" -DataBinding @{
            ItemsSource = New-Binding
        } -View {
            New-GridView -AllowsColumnReorder  -Columns {
                New-GridViewColumn "date" -width 110
            }
        } -DataContext {
                import-csv .\somedata.csv | where {$_.date -gt " "}
        } -On_MouseDoubleClick {
               get-detail $this.selecteditems $window
        } #New-LIstView

        New-ListView -Row 0 -column 1 -Name "Detail" -DataBinding @{
            ItemsSource = New-Binding
        } -View {
            New-GridView -AllowsColumnReorder  -Columns {
                New-GridViewColumn "delta" -width 110
            }
        } -On_MouseDoubleClick {
               get-detail $this.selecteditems $window
        } #New-LIstView

        New-Button -Content "Ok" -IsDefault -Row 1 -Column 0 -width 115 -margin 5 -on_click { close-control}

    } #New-Grid
} -show



Aug 29, 2011 at 10:39 PM

All I had to do to make this work was chagne the -byname parm to -bycontrolname in the following line:

$global:detailListView = $window | Get-ChildControl -ByControlName "Detail"

Thanks!