/// <summary> /// Populate comboBoxModule depending on the selected project /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBoxProject_SelectedIndexChanged(object sender, EventArgs e) { comboBoxModule.Items.Clear(); List <Module> modules = new List <Module>(); if (DbConnector.OpenSQLConnection()) // Open connection to the database { // Connection opened ProjectDataAccess project = new ProjectDataAccess(); int projectId = project.FindProjectByProjectName(comboBoxProject.Text); ModuleDataAccess module = new ModuleDataAccess(); modules = module.FindModuleByProject(Convert.ToInt32(projectId)); } else { // Connection could not be opened MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (modules != null) { // Populate comboBoxes with data foreach (Module m in modules) { comboBoxModule.Items.Add(m.ModuleName); } } }