tags:

views:

16

answers:

0

I have an issue. When I check SelectAllCheckBox all rows of checkbox column in ListView is checked. But when I unchecked one of row checkbox the SelectAllCheckBox is still checked. How to uncheck SelectAllCheckBox if one of row is unchecked? And second question is how to highlight ListView rows, for instabce, blue color when SelectAllCheckBox is checked?

My XAML

<Window.Resources>
  <DataTemplate x:Key="CheckBoxCell">
<StackPanel Orientation="Horizontal">
  <CheckBox Name="chk" IsChecked="{Binding Path=IsSelected, 
    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/>
</StackPanel>
  </DataTemplate>
</Window.Resources>

  <StackPanel Name="Panel1" >
<StackPanel Grid.IsSharedSizeScope="True">
  <CheckBox Name="SelectAllCheckBox" Margin="5">Select All</CheckBox>
</StackPanel>
<ListView Name="ListView1" Background="#f8f8FF" BorderThickness="0" 
           ItemsSource="{Binding Path={}}" Visibility="Visible" Height="Auto" 
           GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler" 
           IsSynchronizedWithCurrentItem="True" 
           VerticalContentAlignment="Center" FontFamily="Tahoma" FontSize="12" 
           Grid.IsSharedSizeScope="False" >
  <ListView.View>
    <GridView AllowsColumnReorder="True" ColumnHeaderContainerStyle="{StaticResource HeaderStyle}">
      <GridViewColumn CellTemplate="{StaticResource CheckBoxCell}" Width="30"/>
      <GridViewColumn ... />
      <GridViewColumn ... />
      <GridViewColumn ... />
    </GridView>
  </ListView.View>
</ListView>

and behind

  Private Sub ListView1_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles ListView1.SelectionChanged
If ListView1.SelectedItems.Count > 0 Then
  For i As Integer = 1 To ListView1.SelectedItems.Count
    Dim TestDataRow As System.Data.DataRowView
    TestDataRow = ListView1.SelectedItems(i - 1)
  Next
End If

End Sub

Thanks.