private void deleteSelectedBarcode_Click(object sender, RoutedEventArgs e) { List <ListViewItems> it = listView.SelectedItems.Cast <ListViewItems>().ToList(); MessageBoxResult res = Xceed.Wpf.Toolkit.MessageBox.Show("Are you sure?. Press 'Yes' to Confirm.", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.No); if (res != MessageBoxResult.Yes) { return; } foreach (ListViewItems item in it) { try { listView.Items.Remove(item); if (ProductTableData.delete1Barcode(item.IMEI, product.ID) == true) { Xceed.Wpf.Toolkit.MessageBox.Show("Barcode deleted successfully. Press ok to exit.", "Exit"); } } catch (Exception ex) { Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "Error"); } } sort(); }