private void btnAddProdToPkg_Click(object sender, EventArgs e) { // Add the selected product/supplier to the package. Multiselect has been set to // false for the data grid view so only one row can be selected at a time. // Return if no row selected if (gridViewOtherProduct.SelectedRows[0] == null) { return; } // Get the package ID of the current package int curCboSelIndex = comboBoxPkgName.SelectedIndex; int pkgId = packages[curCboSelIndex].PackageId; // Obtain the ProductSupplierId from the datagridview int prodSupId = Convert.ToInt32(gridViewOtherProduct.SelectedRows[0].Cells[0].Value); // Then add a new record to the Packages_Products_Suppliers table try { if (PackageDB.AddProductToPackage(pkgId, prodSupId)) { MessageBox.Show("Product/Supplier successfully added to pacakge", "Information"); LoadUIforPackages(); comboBoxPkgName.SelectedIndex = curCboSelIndex; } else { MessageBox.Show("Error adding Product/Supplier to pacakge", "Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }