Я хочу получить / посчитать все проверенные позиции с DataGrid
. У меня 20 предметов в DataGrid
, как вы можете видеть на картинке ниже. Из 20 видимых элементов: 14 или 13. Когда я отмечаю галочкой все пункты, нажимая кнопку Выбрать все , все 20 пунктов отмечаются галочкой. но когда я подсчитываю отмеченные пункты, нажимая Кнопка печати , подсчет показывает, что он помечен только 14. Что случилось? любезно помогите

Datagrid:
<DataGrid HorizontalAlignment="Left" Height="265" Margin="10,74,0,0"
Name="GridTable" AutoGenerateColumns="False" VerticalAlignment="Top" Width="766" CanUserAddRows="False" IsReadOnly="False" SelectionMode="Single" SelectionUnit="Cell">
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="#0073c4"/>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Select" Binding="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTextColumn Header="Code" Width="1*" IsReadOnly="True" Binding="{Binding Code}"/>
<DataGridTextColumn Header="Name" Width="1*" IsReadOnly="True" Binding="{Binding Name}"/>
</DataGrid.Columns>
</DataGrid>
Кнопка Выбрать все:
private void SelectAllBtn_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < GridTable.Items.Count; i++)
{
var item = GridTable.Items[i];
Item itemm = (Item)GridTable.Items[i];
itemm.IsSelected = true;
var mycheckbox = GridTable.Columns[0].GetCellContent(item) as CheckBox;
if (mycheckbox != null)
{
mycheckbox.IsChecked = true;
}
}
}
Нажатие кнопки печати:
private void Print_Click(object sender, RoutedEventArgs e)
{
int count = 0;
for (int i = 0; i < GridTable.Items.Count; i++)
{
var item = GridTable.Items[i];
if (GridTable.Columns[0].GetCellContent(item) as CheckBox != null)
{
var mycheckbox = GridTable.Columns[0].GetCellContent(item) as CheckBox;
if ((bool)mycheckbox.IsChecked)
{
count++;
listTobePrint.Add(tableList[i]);
}
}
}
MessageBox.Show(count.ToString());
Примечание: это MessageBox.Show(count.ToString());
насчитывает 14
Item.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Inventory_Control.Classes
{
class Item : INotifyPropertyChanged
{
private string id;
private string code;
private string name;
private string description;
private string quantity;
private string availableQuantity;
private string unitprice;
private string subtotal;
private string category;
private string type;
private string location;
private string index;
private bool _isSelected;
public string Id
{
get { return id; }
set
{
id = value;
NotifyPropertyChanged("Id");
}
}
public string Code
{
get { return code; }
set
{
code = value;
NotifyPropertyChanged("Code");
}
}
public string Name
{
get { return name; }
set
{
name = value;
NotifyPropertyChanged("Name");
}
}
public string Description
{
get { return description; }
set
{
description = value;
NotifyPropertyChanged("Description");
}
}
public string Quantity
{
get { return quantity; }
set
{
quantity = value;
NotifyPropertyChanged("Quantity");
}
}
public string AvailableQuantity
{
get { return availableQuantity; }
set
{
availableQuantity = value;
NotifyPropertyChanged("AvailableQuantity");
}
}
public string UnitPrice
{
get { return unitprice; }
set
{
unitprice = value;
NotifyPropertyChanged("UnitPrice");
}
}
public string SubTotal
{
get { return subtotal; }
set
{
subtotal = value;
NotifyPropertyChanged("SubTotal");
}
}
public string Category
{
get { return category; }
set
{
category = value;
NotifyPropertyChanged("Category");
}
}
public string Type
{
get { return type; }
set
{
type = value;
NotifyPropertyChanged("Type");
}
}
public string Location
{
get { return location; }
set
{
location = value;
NotifyPropertyChanged("Location");
}
}
public string Index
{
get { return index; }
set
{
index = value;
NotifyPropertyChanged("Index");
}
}
public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
NotifyPropertyChanged("IsSelected");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}