//private void packageDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) //{ // if (e.RowIndex >= 0) // { // DataGridViewRow row = packageDataGridView.Rows[e.RowIndex]; // txtPackageId.Text = row.Cells[0].Value.ToString(); // txtPkgName.Text = row.Cells[1].Value.ToString(); // pkrPkgStartDate.Text = row.Cells[2].Value.ToString(); // pkrPkgEndDate.Text = row.Cells[3].Value.ToString(); // txtPkgDesc.Text = row.Cells[4].Value.ToString(); // txtPkgBasePrice.Text = row.Cells[5].Value.ToString(); // txtPkgAgencyCom.Text = row.Cells[6].Value.ToString(); // List<Bookings> bookingList = new List<Bookings>(); // int packageId = Convert.ToInt32(txtPackageId.Text); // bookingList = PackageDB.DisplayBookingsInGrid(packageId); // bookingsDataGridView.DataSource = bookingList; // } //} private void packageDataGridView_SelectionChanged(object sender, EventArgs e) { if (packageDataGridView.SelectedRows.Count > 0) //execute block code if rows exists in the grid { package = (Package)packageDataGridView.SelectedRows[0].DataBoundItem; //selectedrows[0] gets the row selected by user, //typecast it in Package type & assign it to reference variable, now accesss properties of Package thru package variable //assigns values to controls of the from from corresponding Gridview. this.txtPackageId.Text = package.PackageId.ToString(); txtPkgName.Text = package.PkgName; pkrPkgStartDate.Text = package.PkgStartDate.ToString(); pkrPkgEndDate.Text = package.PkgEndDate.ToString(); txtPkgBasePrice.Text = package.PkgBasePrice.ToString(); if (package.PkgDesc == null) { txtPkgDesc.Text = ""; } else { txtPkgDesc.Text = package.PkgDesc.ToString(); } if (package.PkgAgencyCommission == null) { txtPkgAgencyCom.Text = ""; } else { txtPkgAgencyCom.Text = package.PkgAgencyCommission.ToString(); } int packageId = Convert.ToInt32(txtPackageId.Text); //populating related products in product list view products = PackageDB.DisplayProductsInList(packageId); lstProductsonPackagefrm.DataSource = products; //populating related suppliers in product list view suppliers = PackageDB.DisplaySuppliersInList(packageId); lstSuppliersonPackagefrm.DataSource = suppliers; //popualting related bookings in booking gridview List <Bookings> bookingList = new List <Bookings>(); bookingList = PackageDB.DisplayBookingsInGrid(packageId); bookingsDataGridView.DataSource = bookingList; } }