Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF iterate through items in a listview
    text
    copied!<p>I have a <code>ListView</code> with a <code>CheckBox</code> as one of the columns, bound to a boolean property of a custom object. I'm trying to figure out how to iterate through the items in the <code>ListView</code> and check all the checkboxes. What I have so far is below:</p> <p>XAML:</p> <pre><code>&lt;ListView x:Name="MyListView" DockPanel.Dock="Top" Height="275" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Header="Enabled"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;CheckBox IsChecked="{Binding Path=IsChecked}" Click="CheckBox_Click" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; </code></pre> <p>VB.NET:</p> <pre><code>Private Sub SelectAll_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles SelectAll.Click Dim currSelected As Integer = MyListView.SelectedIndex MyListView.SelectAll() For ixItem As Integer = 0 To MyListView.SelectedItems.Count - 1 coItems(ixItem).IsChecked = True Next MyListView.SelectedIndex = currSelected End Sub </code></pre> <p>I have a hunch this is actually pretty easy, and I'm just missing one line somewhere. Thanks for the help!</p> <p><strong>UPDATE:</strong> The problem more specifically is that the checkboxes that are visible when the button is pressed aren't being displayed as checked, but the ones that aren't visible (because the user needs to scroll down to see them) are displayed as checked.</p> <p><strong>UPDATE 2:</strong> As requested, here is the PropertyChanged code. I'm still fairly new to WPF, I haven't done much with INotifyPropertyChanged before.</p> <pre><code>Public Property blnIsChecked() As Boolean Get Return _blnIsChecked End Get Set(ByVal value As Boolean) _blnIsChecked = value End Set End Property Public Event PropertyChangedHandler(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload