public DataGridView getDGV() { dataGridView1.DataSource = null; DataTable dt = new DataTable(); int criteriaCount = 0; // DYNAMIC COLUMN dt.Columns.Add(new DataColumn("Alternative Name", typeof(string))); foreach (Criteria criteria in criteriaController.getCriteriaList(currentTopicId)) { criteriaCount++; string columnName = criteria.criteriaName; if (criteria.criteriaUnit != "") { columnName += " (" + criteria.criteriaUnit + ")"; } if (criteria.isBoolean) { dt.Columns.Add(new DataColumn(columnName, typeof(Boolean))); } else { dt.Columns.Add(new DataColumn(columnName, typeof(double))); } } // DYNAMIC ROW foreach (string alternativeName in alternativeListController.getAlternativeList(currentTopicId)) { DataRow row = dt.NewRow(); row["Alternative Name"] = alternativeName; foreach (Criteria criteria in criteriaController.getCriteriaList(currentTopicId)) { string columnName = criteria.criteriaName; if (criteria.criteriaUnit != "") { columnName += " (" + criteria.criteriaUnit + ")"; } row[columnName] = alternativeListController.valueLookup(criteria.criteriaId, alternativeName); } dt.Rows.Add(row); } dataGridView1.DataSource = dt; dataGridView1.ClearSelection(); dataGridView1.ReadOnly = true; return(dataGridView1); }
private void AddAlternativeForm_Load(object sender, EventArgs e) { foreach (var form in this.Owner.MdiChildren) { if (form.GetType() == typeof(AlternativeListForm)) { alternativeListForm = (AlternativeListForm)form; } } mainForm = (MainForm)this.Owner; criteriaController = new CriteriaController(); alternativeListController = new AlternativeListController(); currentTopicId = alternativeListForm.getCurrentTopicId(); currentUserName = alternativeListForm.getCurrentUserName(); if (action == "Edit") { this.Text = "Edit Alternative: " + selectedAlternativeName; txtAlternativeName.Text = selectedAlternativeName; btnAdd.Visible = false; btnEdit.Visible = true; } else if (action == "Add") { this.Text = "Add Alternative"; txtAlternativeName.Text = ""; btnAdd.Visible = true; btnEdit.Visible = false; } flowLayoutPanel1.Controls.Clear(); foreach (Criteria criteria in criteriaController.getCriteriaList(currentTopicId)) { int criteriaId = criteria.criteriaId; string criteriaName = criteria.criteriaName; string criteriaUnit = criteria.criteriaUnit; bool isBoolean = criteria.isBoolean; double value = 0; if (action == "Edit") { value = alternativeListController.valueLookup(criteriaId, selectedAlternativeName); } AddAlternativeUserControl addAlternativeUserControl = new AddAlternativeUserControl(criteriaId, criteriaName, criteriaUnit, isBoolean, value); addAlternativeUserControl.Parent = flowLayoutPanel1; flowLayoutPanel1.Controls.Add(addAlternativeUserControl); } }