private void return_datagridview_SelectionChanged(object sender, EventArgs e) { if (return_datagridview.SelectedRows.Count > 0) { DataGridViewRow currentRow = return_datagridview.SelectedRows[0]; if (currentRow != null) { String originAbv = currentRow.Cells["originAbv"].Value.ToString(); String leg1destAbv = currentRow.Cells["leg1dest"].Value.ToString(); String leg1deptTime = currentRow.Cells["leg1DeptTime"].Value.ToString(); String leg1ArrivalTime = currentRow.Cells["leg1ArrivalTime"].Value.ToString(); int leg1id = (int)currentRow.Cells["leg1id"].Value; Console.WriteLine("-------------->" + leg1id); return_leg1_selectedflight_label.Text = originAbv + "-->" + leg1destAbv; return_leg1_departure_label.Text = "Departure: " + leg1deptTime; return_leg1_arrival_label.Text = "Arrival: " + leg1ArrivalTime; double cost_total_return = 0; double cost_leg1 = FormDatabaseHelper.getCostFromBookingTable(Convert.ToInt32(leg1id)); cost_total_return += cost_leg1; string cost_str_return = "Cost: " + cost_leg1.ToString(); String leg2origin = ""; //6 String leg2dest = ""; //7 String leg2deptTime = ""; //8 String leg2arrivalTime = ""; //9 double cost_leg2 = 0; int leg2id = (int)currentRow.Cells["leg2id"].Value; return_leg1 = 0; return_leg2 = 0; return_leg1 = leg1id; return_leg2 = leg2id; if (leg2id != 0) { leg2origin = currentRow.Cells["leg2origin"].Value.ToString(); leg2dest = currentRow.Cells["leg2Dest"].Value.ToString(); leg2deptTime = currentRow.Cells["leg2deptTime"].Value.ToString(); leg2arrivalTime = currentRow.Cells["leg2ArrivalTime"].Value.ToString(); return_leg2_groupbox.Show(); return_leg2_selectedflight_label.Text = leg2origin + "-->" + leg2dest; return_leg2_departure_label.Text = "Departure: " + leg2deptTime; return_leg2_arrival_label.Text = "Arrival: " + leg2arrivalTime; cost_leg2 = FormDatabaseHelper.getCostFromBookingTable(Convert.ToInt32(leg2id)); cost_str_return = cost_str_return + " + " + cost_leg2.ToString() + " + 8 = "; cost_total_return += (cost_leg2 + 8); cost_str_return = cost_str_return + cost_total_return.ToString(); } else { return_leg2_groupbox.Hide(); } return_cost_label.Text = cost_str_return; } } }