首页 新闻 会员 周边 捐助

控件开发UI编辑器同步属性问题

0
悬赏园豆:50 [已关闭问题] 关闭于 2012-07-12 17:56

我做了个复合控件,暂且命名为xyz,该控件包含个treeview控件,该控件有个属性Items返回的是子控件treeview的Nodes属性,我为Items属性编写了个编辑器,代码如下:


        private class DropDownTreeNodeCollectionEditor :UITypeEditor
        {
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {

                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                IDesignerHost service = (IDesignerHost)context.GetService(typeof(IDesignerHost));
                DropDownTreeView dropDownTreeView = (DropDownTreeView)context.Instance;
                TreeView treeView = dropDownTreeView._treeView;//子控件

                if (context.Container.Components["dropTreeView"] == null) context.Container.Add(treeView, "dropTreeView");

                TreeViewDesigner treeViewDesigner = (TreeViewDesigner)service.GetDesigner(context.Container.Components["dropTreeView"]);
 
                edSvc.ShowDialog(GetTreeNodeCollectionEditorForm(treeView, treeViewDesigner));

                return value;

          }

     //获取TreeNode节点编辑器窗体

            private System.Windows.Forms.Form GetTreeNodeCollectionEditorForm(System.Web.UI.WebControls.TreeView treeView, TreeViewDesigner treeViewDesigner)
            {
                Assembly asm = Assembly.Load("System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
                System.Windows.Forms.Form form = (System.Windows.Forms.Form)asm.CreateInstance("System.Web.UI.Design.WebControls.TreeNodeCollectionEditorDialog", false, BindingFlags.CreateInstance, null, new object[] { treeView, treeViewDesigner }, null, null);
                return form;
            }

            public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
            {
                if (context != null)
                    return UITypeEditorEditStyle.Modal;
                return base.GetEditStyle(context);
            }
        }

当我点击Items属性后的按钮时,能弹出treeview节点编辑器窗体,但是增加节点后,能保存在这个窗体中,但是节点不能自动添加到源视图该控件的Items属性当中,即不能保存添加的节点,不知各位有什么办法能同步属性,是要回调什么方法吗?

静女的主页 静女 | 初学一级 | 园豆:27
提问于:2012-05-24 15:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册