Dynamic Form Control Properties

I am creating a capture form on the fly based on a set of metadata stored in an EAV type schema.

My problem is loading the data back into the control and specifically the combobox winforms.

It also uses the Entity Framework for data bound to the control.

  • Check if control exists, otherwise create. for each displayed property set their own values. i.e. Datasource, DisplayMember, ValueMember, etc.

  • Does Load exist in the SelectedValue property? this is where it fails?

When inspecting the object, it seems that none of the previous values, including the data source, have been loaded yet? But does the combobox really show the values ​​after rendering?

Here are some code snippets.

Type oType = Type.GetType("System.Windows.Forms.ComboBox");
if (oControlObject == null)
{
  oControlObject = (Control)Activator.CreateInstance(oType);
  oControlObject.Tag = item;
  oControlObject.CreateControl();
}

...Loop to set Datasource, DisplayMember & ValueMember ...

if (property.IsReadProperty.Value && value != null)
{
  PropertyInfo propSet = oType.GetProperty(property.PropertyName); //PropertyName here is "SelectedValue"
  propSet.SetValue(oControlObject, value.Value, null);
}

      

+1


a source to share


1 answer


It worked. The problem is that the control doesn't initialize until it is displayed on the form, so no items will be collected even if the datasource is set.



Create a dynamic form first, then write the save values, iterate again with controls ... not gracefully, but it works until I have another solution.

0


a source







All Articles