public static void FillControl(Dictionary <string, string> collection, Control control, IDefinitionSavable saveable) { if (control.Tag != null && GetControlDefinition(control, out string attribute, out bool required, out string defaultvalue)) { if (!collection.TryGetValue(attribute, out string value)) { value = defaultvalue; } if (control is CheckBox chkbox) { bool.TryParse(value, out bool chk); chkbox.Checked = chk; if (saveable != null) { chkbox.CheckedChanged += (s, e) => saveable.Save(false); } } else if (control is TextBox txt) { txt.Text = value; if (saveable != null) { new TextBoxEventHandler(txt, saveable).Attach(); } } else if (control is ComboBox cmb) { object selitem = null; foreach (var item in cmb.Items) { if (item is IXRMControlItem) { if (((IXRMControlItem)item).GetValue() == value) { selitem = item; break; } } } if (selitem != null) { cmb.SelectedItem = selitem; } else if (value != null && cmb.Items.IndexOf(value) >= 0) { cmb.SelectedItem = value; } else { cmb.Text = value; } if (saveable != null) { new ComboBoxEventHandler(cmb, saveable).Attach(); } } } }
public TextBoxEventHandler(TextBox txt, IDefinitionSavable saveable) { this.txt = txt; this.saveable = saveable; }
public ComboBoxEventHandler(ComboBox cmb, IDefinitionSavable saveable) { this.cmb = cmb; this.saveable = saveable; }
public static void FillControls(Dictionary <string, string> collection, Control.ControlCollection controls, IDefinitionSavable saveable) { if (controls?.Count == 0) { return; } controls.OfType <Control>().Where(y => y.Tag != null).OrderBy(y => y.TabIndex).ToList().ForEach(c => FillControl(collection, c, saveable)); controls.OfType <Panel>().OrderBy(p => p.TabIndex).ToList().ForEach(p => FillControls(collection, p.Controls, saveable)); }