/// <summary> /// Deletes selected item from data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void delete_btn_Click(object sender, RoutedEventArgs e) { if (dataGridView1.SelectedIndex < newLstInvoice.Count && dataGridView1.SelectedItem != null) { //create and instanitate a new Invoice object clsInvoice Invoice = new clsInvoice(); //set the new object called Invoice to the selected item in the datagrid called dataGridView Invoice = (clsInvoice)dataGridView1.SelectedItem; bIsDeleting = true; //delete the Line item at the current selected item. MainLogic.DeleteLineItemSQL(Invoice.iInvoiceNum); //delete the Invoice at the current selected item. MainLogic.DeleteInvoiceSQL(Invoice.iInvoiceNum); //set the new list called newLstInvoice to get the lstInvoice that will return the data in the dataset. newLstInvoice = MainLogic.GetInvoice(); //bind the data from our new list into the datagrid called dataGridView dataGridView1.ItemsSource = newLstInvoice; bIsDeleting = false; //commits changes to database. MainLogic.ds.AcceptChanges(); //refresh items in the datagrid called dataGridView dataGridView1.Items.Refresh(); } }
private void dataGridView_SelectionChanged(object sender, SelectionChangedEventArgs e) { newLstLineItems.Clear(); dataGridView2.Items.Refresh(); //checks to make sure that we cannot select a row without invoice data. if (dataGridView1.SelectedIndex < newLstInvoice.Count && bIsDeleting == false) { clsInvoice Invoice = new clsInvoice(); Invoice = (clsInvoice)dataGridView1.SelectedItem; newLstLineItems = MainLogic.GetLineItems(Invoice.iInvoiceNum); dataGridView2.ItemsSource = newLstLineItems; dataGridView2.Columns[1].Visibility = System.Windows.Visibility.Hidden; } }