private void SelectQuestionForm_Load(object sender, EventArgs e) { dataset = ds; dataset.QuestionsEx.Clear(); dbObject.GetAllQuestionsEx(dataset); int count = 0; for (int i = 0; i < dataset.QuestionsEx.Count; ++i) { if (dataset.QuestionsEx[i].SetId == setId) { dataset.QuestionsEx[i].Delete(); count++; continue; } if (!dataset.QuestionSetsEx.FindById(setId).IsQuestionTypeIdNull()) { if (dataset.QuestionsEx[i].TypeId != dataset.QuestionSetsEx.FindById(setId).QuestionTypeId) { dataset.QuestionsEx[i].Delete(); count++; continue; } } } if (count == dataset.QuestionsEx.Count) { MessageBox.Show("Not valid to add question in database.", "Select question", MessageBoxButtons.OK, MessageBoxIcon.Warning); { DialogResult = DialogResult.Cancel; } } questionDataGrid.DataSource = dataset; type.DataSource = dataset; subType.DataSource = dataset; difficultyLevelId.DataSource = dataset; questionDataGrid.Update(); }