简体   繁体   English

动态表单控件属性

[英]Dynamic Forms Control Properties

I'm creating a capture form on the fly based on a set of metadata held in a EAV type schema. 我正在基于EAV类型架构中保存的一组元数据动态创建捕获表单。

My trouble is in load the data back to the control, and in particular a winforms combobox. 我的麻烦是将数据加载回控件,尤其是Winforms组合框。

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. 为每个映射的属性设置其值。 ie Datasource, DisplayMember, ValueMember, etc... 即数据源,DisplayMember,ValueMember等...

  2. Load value is exists to SelectedValue property? 加载值是否存在于SelectedValue属性中? 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);
}

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. 首先建立动态表单,然后通过再次遍历控件来填充保存值...虽然不雅致,但是可以工作,直到我有了另一个解决方案为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM