private void btnDelete_Click(object sender, EventArgs e) { foreach (var item in checkedListBox.CheckedItems) { int id = _context.ServicetoPackets.FirstOrDefault(c => c.Service.Service_Name == item.ToString()).Id; ServicetoPacket servicetoPacket = _context.ServicetoPackets.Find(id); _context.ServicetoPackets.Remove(servicetoPacket); } _context.SaveChanges(); FillDataGridView(); ClearAllField(); }
private void dtgv_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { int id = (int)dtgv.Rows[e.RowIndex].Cells[0].Value; ServicetoPacket servicetoPacket = _context.ServicetoPackets.Find(id); SelectedData = servicetoPacket; cmbPacket.Text = servicetoPacket.Packet.Packet_Name; for (int i = 0; i < checkedListBox.Items.Count; i++) { checkedListBox.SetItemCheckState(i, CheckState.Unchecked); foreach (var items in _context.ServicetoPackets.Where(sp => sp.Packet_Id == servicetoPacket.Packet_Id).ToList()) { if (checkedListBox.Items[i].ToString() == items.Service.Service_Name) { checkedListBox.SetItemCheckState(i, CheckState.Checked); } } } }