views:

91

answers:

1

I'm creating a capture form on the fly based on a set of metadata held in a EAV type schema.

My trouble is in load the data back to the control, and in particular a winforms combobox.

Also using Entity Framework for the data that is bound to the control.

  1. Check is control exist, else create. for each mapped property set their values. i.e. Datasource, DisplayMember, ValueMember, etc...

  2. Load value is exists to SelectedValue property? this is where is fails?

On inspection of the object it seems as if none of the previous values including the datasource has been loaded yet? But the combobox does show the values once rendered?

Here are some snippets of the code.

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);
}
A: 

Got it working. The problem is that the control is not initialized until it is rendered on the form, thus no items collection, even though the datasource is set.

Built up the dynamic form first and then populated the save values by iterating through the controls again... not elegant but it works, until i have another solution.

Jan de Jager