private static void UpdateControlValue(FillInfo info, Control c) { /// Getting the value of the field. All fields are strings but they can be null or empty so we need /// to check this state object value = info.Field.GetValue(info.Client); if (value != null) { /// if the value of the field is not null we must convert it to the form needed to the Control using IValueConverter IValueConverter conv = info.PositionAttr.Converter; /// value of the field in form for the Control object val = null; if (conv != null) val = conv.ConvertFromString(value.ToString()); if (val != null) { try { if (c is TextBox) c.Text = (string)val; else if (c is ComboBox) { c.Text = (string)val; if (!string.IsNullOrEmpty(info.PositionAttr.ListerName)) { ((ComboBox)c).Items.AddRange(ListersHolder.Holder[info.PositionAttr.ListerName].Enum.ToArray()); if (info.PositionAttr.OnlyFromList) { ((ComboBox)c).DropDownStyle = ComboBoxStyle.DropDownList; ((ComboBox)c).SelectedItem = FindComboItem((ComboBox)c, (string)val); } } } else if (c is DateTimePicker) (c as DateTimePicker).Value = (DateTime)val; else if (c is CheckBox) (c as CheckBox).Checked = (bool)val; } catch { throw new Exception("IValueConverter returned incorrect object " + info.Field.Name); } } } }
private static void UpdateFieldValue(FillInfo info, Control c) { if (c is TextBox) { info.Field.SetValue(info.Client, c.Text); } else if (c is ComboBox) { info.Field.SetValue(info.Client, GetComboValue(c as ComboBox)); } else if (c is DateTimePicker) { DateTime dt = ((DateTimePicker)c).Value; IValueConverter conv = info.PositionAttr.Converter; if (conv != null) { string val = conv.ConvertToString(dt); info.Field.SetValue(info.Client, val); } } }
private static Control CreateAndStyleControl(FillInfo info) { Control c = info.PositionAttr.GetControl(); UpdateControlValue(info, c); if (c is ComboBox) { (c as ComboBox).DropDownWidth *= 2; } c.Padding = new Padding(5); c.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; c.Tag = info; c.TextChanged += new EventHandler(ControlTextChanged); return c; }