(学)新版动态表单研发,阶段成果----3

汇报一下今天的工作:

1、解决控件数据绑定问题;

2、解决窗体中数据来源问题;

3、解决控件目标数据源与窗体数据集交互问题。(怎么越写越像学校的论文呢、乱糟糟)

4、说说组件之间数据源共享的方法吧:

    窗体、及各组件采用继承方式,加增自己想要的DataSource属性,属性内容根据需求自己来写,我这目前是一个结构   

 public struct Entity
    {
        public string Name { get; set; }
        public string SelectCommand { get; set; }
        public string Type { get; set; }
        public string PrimaryKey { get; set; }
        public string ParentKey { get; set; }
        public DataSet DataSource { get; set; }
    }

   

    下面是使用方法了,绑定到控件属性上,就会得到你要的效果了。PS:我这份代码有点误人子弟,因为有个

                ProManager pm = (ProManager)context.Instance;
                IDesignerHost host 
= pm.Host;

     其实是可以通过其它方式来

                比如:

                IDesignerHost host = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost));

      来实现的,但因为我中间导了一手,做了些其它的事,所以这个component已经不是你所看到的component了,不得已采用上述方式实现。

public class EditorEntity : UITypeEditor
    {
        
public override UITypeEditorEditStyle GetEditStyle(
           ITypeDescriptorContext context)
        {
            
return UITypeEditorEditStyle.Modal;
        }

        
public override object EditValue(ITypeDescriptorContext context,
            IServiceProvider provider, 
object value)
        {
            FormDataSource form 
= new FormDataSource();
            
if (value!=null)
                form.DataSource 
= (Dictionary<string,Entity>)value;
            
else
                form.DataSource 
= new Dictionary<string,Entity>();
            form.ShowDialog();
            value 
= form.DataSource;
            
return value;
        }
    }
    
public class EditorDataBinding : UITypeEditor
    {
        
public override UITypeEditorEditStyle GetEditStyle(
           ITypeDescriptorContext context)
        {
            
return UITypeEditorEditStyle.DropDown;
        }

        
public override object EditValue(ITypeDescriptorContext context,
            IServiceProvider provider, 
object value)
        {
            IWindowsFormsEditorService wfes 
= provider.GetService(
                
typeof(IWindowsFormsEditorService)) as
                IWindowsFormsEditorService;
            
if (wfes != null)
            {

                ProManager pm 
= (ProManager)context.Instance;
                IDesignerHost host 
= pm.Host;
                Dictionary
<string,Entity> ls = (host.RootComponent as FormEx).DataSource;

                FormDataBinding _formDataSet 
= new FormDataBinding(ls, value==null ?"":value.ToString());
                _formDataSet._wfes 
= wfes;
                wfes.DropDownControl(_formDataSet);
                value 
= _formDataSet.DataMember;
            }
            
return value;
        }
    }

 

      

 

4、上个图

 

本来想先开始控件布局属性的存储、加载来着,但总感觉顺手把DataGrid、TreeView的数据绑定做完效果会更好,所以我决定。

后续工作:

1、这一、两天完成DataGrid、TreeView的数据绑定问题。

 

posted @ 2011-05-17 15:19  禹过天晴  阅读(448)  评论(0编辑  收藏  举报