private void bnShowCart_Click(object sender, EventArgs e) { // XXX Show Cart Button event handler while (true) { try { // to capture an exception from SelectedIndex/SelectedItem of carDisplay cartDialog.ClearDisplayItems(); //cartDialog.AddDisplayItems(null); // null is a dummy argument BookShopControl.showCartInformation(cartDialog); switch (cartDialog.Display()) { case DialogReturn.CheckOut: // check out // XXX BookShopControl.checkOutCustomer(); return; case DialogReturn.ReturnBook: // remove a book // XXX BookShopControl.removeBookFromCustomerCart(BookShopControl.LoggedinCustomer.currentCart.itemsPurchased[cartDialog.SelectedIndex].purchaseBook.isbn); continue; case DialogReturn.Done: // cancel return; } } catch (BookShopException bsex) { MessageBox.Show(this, bsex.ErrorMessage); continue; } catch (NullReferenceException nex) { MessageBox.Show(this, nex.Message); return; } } }