private void barcodeSerial_KeyDown(object sender, KeyEventArgs e) { int quan = 0; if (e.Key == Key.Enter && barcodeSerial.Text != "") { if (IsAlreadyExists(barcodeSerial.Text) == true) { Xceed.Wpf.Toolkit.MessageBox.Show("The barcode is already in the list. Pres ok to exit.", "Duplicate Barcode", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); barcodeSerial.Clear(); return; } else if (ProductTableData.hasBarcodeinDB(barcodeSerial.Text) == true) { Xceed.Wpf.Toolkit.MessageBox.Show("The barcode is already in the Database. Pres ok to exit.", "Duplicate Barcode in DB", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); barcodeSerial.Clear(); return; } else if (sameBarcode.IsChecked == true && listView.Items.Count >= 1) { Xceed.Wpf.Toolkit.MessageBox.Show("You can add only one barcode. Pres ok to exit.", "Barcode", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); barcodeSerial.Clear(); return; } else if (uniqBarcode.IsChecked == true && int.TryParse(quantity.Text, out quan) == true && listView.Items.Count > quan - 1) { Xceed.Wpf.Toolkit.MessageBox.Show("You cannot add barcode more than quantity. Press ok to exit.", "Barcode", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); barcodeSerial.Clear(); return; } listView.Items.Add(new ListViewItems(listView.Items.Count + 1, barcodeSerial.Text, "NONE")); listView.SelectedIndex = listView.Items.Count - 1; listView.ScrollIntoView(listView.SelectedItem); barcodeSerial.Clear(); } if (e.Key == Key.Enter && quan == listView.Items.Count && product.Unique_Barcode.StartsWith("Y")) { var uie = e.OriginalSource as UIElement; e.Handled = true; uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); } }