Me aparece este error en un DataGrid al usar un textbox para buscar un nombre me muestra el que encuentre pero al dar clic a la celda que quiero editar aparece ese error. al cargar la ventana si funciona pero al usar un filtro y carga el resultado las filas no tiene esta propiedad eso creo lo que pasa
DataGrid
<DataGrid x:Name="dataGrid"
ItemsSource="{Binding}"
Loaded="DataGrid_Loaded"
Grid.Row="3"
FontSize="15" AutoGenerateColumns="False" Margin="56,26,36,26" ColumnWidth="*" CurrentCellChanged="dataGrid_CurrentCellChanged" CanUserAddRows="False"
>
<DataGrid.Columns>
<DataGridTextColumn Header="Numero de parte" Binding="{Binding PartNumber}" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding id}" ClipboardContentBinding="{x:Null}" Header="id" IsReadOnly="True" Visibility="Hidden"/>
<DataGridTextColumn Header="Area" Binding="{Binding Area}" IsReadOnly="True"/>
<DataGridTextColumn Header="Familia" Binding="{Binding Reference}" IsReadOnly="True"/>
<DataGridTextColumn Header="Descripcion" Binding="{Binding Description}"/>
<DataGridTextColumn Header="Minimo" Binding="{Binding Minimo}"/>
<DataGridTextColumn Header="Critico" Binding="{Binding Critico}"/>
<DataGridCheckBoxColumn Binding="{Binding Activo}" ClipboardContentBinding="{x:Null}" Header="Activo"/>
</DataGrid.Columns>
</DataGrid>
eventos DataGrid
private void DataGrid_Loaded(object sender, RoutedEventArgs e)
{
SMDWarehouseEntities db = new SMDWarehouseEntities();
var de = (DataGrid)sender;
de.ItemsSource = db.ConfigInventories.AsNoTracking().ToList();
}
private void dataGrid_CurrentCellChanged(object sender, EventArgs e)
{
if (dataGrid.SelectedIndex < 0) return;
using (SMDWarehouseEntities db = new SMDWarehouseEntities())
{
var row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(dataGrid.SelectedIndex);
var DataCof = (ConfigInventory)row.Item;
db.Entry(DataCof).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
}
}
el evento del texbox que hace la busqueda y actualiza los datos
private void tb_Buscar_TextChanged(object sender, TextChangedEventArgs e)
{
SMDWarehouseEntities db = new SMDWarehouseEntities();
string Word = tb_Buscar.Text;
var data = db.ConfigInventories.AsNoTracking().ToList();
dataGrid.ItemsSource = (Word == "" || Word == null)? data : data.Where(x => x.PartNumber.Equals(Word));
}