private void DeleteItemCategory()
{
List rowsToDelete = new List();
foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
{
if (rowsToDelete.Contains(cell.RowIndex) == false)
rowsToDelete.Add(cell.RowIndex);
}
rowsToDelete = rowsToDelete.OrderByDescending(rowIndex => rowIndex).ToList();
foreach (Int32 rowIndex in rowsToDelete)
{
if (dataGridView1.Rows[rowIndex].Cells[0].Value != null)
{
a = _context.ItemCategories.Find(dataGridView1.Rows[rowIndex].Cells[0].Value);
}
dataGridView1.Rows.RemoveAt(rowIndex);
}
_context.Entry(a).State = EntityState.Deleted;
rowsToDelete.Clear();
_context.SaveChanges();
}
maaf ya masih belum rapi, tapi tenang aja esok kan ku update lagi... :) Have a nice coding!

Post a Comment