/// <summary>Creates a form containing editable data</summary> /// <param name="BindSrc">Binding source to use</param> /// <param name="ParentControl">Control where to add items. A new panel is created there.</param> /// <param name="MultiLineCols">Columns containig multiline data</param> /// <param name="MultiFieldCols">Columns containing multiple data such as more than 1 objective, etc.</param> /// <param name="ComboboxCols">Columns which should be combo boxes</param> /// <param name="ComboboxItems">Data to populate each combobox</param> public static void CreateForm(BindingSource BindSrc, Control ParentControl, List <string> MultiLineCols, List <string> MultiFieldCols, List <string> ComboboxCols, List <List <string> > ComboboxItems) { //Creates a panel to hold everything Panel panel = new Panel(); panel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; panel.Top = 0; panel.Left = 0; panel.Width = ParentControl.Width; panel.Height = ParentControl.Height; panel.AutoScroll = true; ParentControl.Controls.Add(panel); DataTable t = (DataTable)BindSrc.DataSource; int top = 10; int left = 40; foreach (DataColumn c in t.Columns) { if (c.ColumnName != "Count") { Label lbl = new Label(); lbl.AutoSize = true; lbl.Text = c.ColumnName; lbl.Refresh(); lbl.Top = top + 3; lbl.Left = left; if (ComboboxCols != null && ComboboxCols.IndexOf(c.ColumnName) < 0) { TextBox txt = new TextBox(); txt.Top = top; txt.Left = lbl.Left + lbl.Width + 220; txt.Width = panel.Width / 2; txt.DataBindings.Add("Text", BindSrc, c.ColumnName, false, DataSourceUpdateMode.OnPropertyChanged); top = txt.Top + txt.Height + 10; if (MultiLineCols.IndexOf(c.ColumnName) >= 0) { txt.Multiline = true; txt.ScrollBars = ScrollBars.Vertical; txt.Height = 120; top = txt.Top + txt.Height + 10; } else if (MultiFieldCols.IndexOf(c.ColumnName) >= 0) { XMLFuncs.MultiField mf = new XMLFuncs.MultiField(txt, panel); top = mf.GetNextTop() + 10; } panel.Controls.Add(txt); } else { //Combobox ComboBox cmb = new ComboBox(); cmb.Top = top; cmb.Left = lbl.Left + lbl.Width + 220; cmb.Width = panel.Width / 2; cmb.DataBindings.Add("Text", BindSrc, c.ColumnName, false, DataSourceUpdateMode.OnPropertyChanged); top = cmb.Top + cmb.Height + 10; //cmb.Font = new Font(cmb.Font.FontFamily, 10); cmb.DropDownStyle = ComboBoxStyle.DropDownList; foreach (string s in ComboboxItems[ComboboxCols.IndexOf(c.ColumnName)]) { cmb.Items.Add(s); } panel.Controls.Add(cmb); } panel.Controls.Add(lbl); } } }
/// <summary>Creates a form containing editable data</summary> /// <param name="BindSrc">Binding source to use</param> /// <param name="ParentControl">Control where to add items. A new panel is created there.</param> /// <param name="MultiLineCols">Columns containig multiline data</param> /// <param name="MultiFieldCols">Columns containing multiple data such as more than 1 objective, etc.</param> /// <param name="ComboboxCols">Columns which should be combo boxes</param> /// <param name="ComboboxItems">Data to populate each combobox</param> public static void CreateForm(BindingSource BindSrc, Control ParentControl, List<string> MultiLineCols, List<string> MultiFieldCols, List<string> ComboboxCols, List<List<string>> ComboboxItems) { //Creates a panel to hold everything Panel panel = new Panel(); panel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; panel.Top = 0; panel.Left = 0; panel.Width = ParentControl.Width; panel.Height = ParentControl.Height; panel.AutoScroll = true; ParentControl.Controls.Add(panel); DataTable t = (DataTable)BindSrc.DataSource; int top = 10; int left = 40; foreach (DataColumn c in t.Columns) { if (c.ColumnName != "Count") { Label lbl = new Label(); lbl.AutoSize = true; lbl.Text = c.ColumnName; lbl.Refresh(); lbl.Top = top + 3; lbl.Left = left; if (ComboboxCols != null && ComboboxCols.IndexOf(c.ColumnName) < 0) { TextBox txt = new TextBox(); txt.Top = top; txt.Left = lbl.Left + lbl.Width + 220; txt.Width = panel.Width / 2; txt.DataBindings.Add("Text", BindSrc, c.ColumnName, false, DataSourceUpdateMode.OnPropertyChanged); top = txt.Top + txt.Height + 10; if (MultiLineCols.IndexOf(c.ColumnName) >= 0) { txt.Multiline = true; txt.ScrollBars = ScrollBars.Vertical; txt.Height = 120; top = txt.Top + txt.Height + 10; } else if (MultiFieldCols.IndexOf(c.ColumnName) >= 0) { XMLFuncs.MultiField mf = new XMLFuncs.MultiField(txt, panel); top = mf.GetNextTop() + 10; } panel.Controls.Add(txt); } else { //Combobox ComboBox cmb = new ComboBox(); cmb.Top = top; cmb.Left = lbl.Left + lbl.Width + 220; cmb.Width = panel.Width / 2; cmb.DataBindings.Add("Text", BindSrc, c.ColumnName, false, DataSourceUpdateMode.OnPropertyChanged); top = cmb.Top + cmb.Height + 10; //cmb.Font = new Font(cmb.Font.FontFamily, 10); cmb.DropDownStyle = ComboBoxStyle.DropDownList; foreach (string s in ComboboxItems[ComboboxCols.IndexOf(c.ColumnName)]) cmb.Items.Add(s); panel.Controls.Add(cmb); } panel.Controls.Add(lbl); } } }