private void barcodeimeiTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter && barcodeimeiTextBox.Text != "") { stockHistoryDG.Items.Clear(); salesHistoryDG.Items.Clear(); try { //for stock datagrid Barcode bar = ProductTableData.getBarcode(barcodeimeiTextBox.Text); Product product = bar.Product; stockHistoryDG.Items.Add(product); //for sales datagrid Gift gif = bar.Gift; if (gif != null) { Customer_Sale cus_sale = gif.Customer_Sale; SalesHistoryDataGrid salesHis = new SalesHistoryDataGrid(cus_sale, gif.Barcode); salesHistoryDG.Items.Add(salesHis); } } catch (Exception ex) { Xceed.Wpf.Toolkit.MessageBox.Show("No product found. Press 'OK' to exit.\n\nDetailed Error:" + ex.Message, "Empty Product", MessageBoxButton.OK, MessageBoxImage.Error); } } }