none
ControlDesigner中数据绑定项 的属性设置 RRS feed

  • 问题

  •     [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
        public class ComboTextBoxDesigner : System.Windows.Forms.Design.ControlDesigner
        {
            private DesignerActionListCollection actionLists;

            // Use pull model to populate smart tag menu.
            public override DesignerActionListCollection ActionLists
            {
                get
                {
                    if (null == actionLists)
                    {
                        actionLists = new DesignerActionListCollection();
                        actionLists.Add(new ComboTextBoxDesignerActionList(this.Component));
                    }
                    return actionLists;
                }
            }
        }

        public class ComboTextBoxDesignerActionList : System.ComponentModel.Design.DesignerActionList
        {
            private ComboTextBox comboTextBox;

            private DesignerActionUIService designerActionUISvc = null;

            public ComboTextBoxDesignerActionList(IComponent component)
                : base(component)
            {
                this.comboTextBox = component as ComboTextBox;
                this.designerActionUISvc = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
            }

            // Helper method to retrieve control properties. Use of
            // GetProperties enables undo and menu updates to work properly.
            private PropertyDescriptor GetPropertyByName(String propName)
            {
                PropertyDescriptor prop;
                prop = TypeDescriptor.GetProperties(comboTextBox)[propName];
                if (null == prop)
                    throw new ArgumentException("Matching ComboTextBox property not found!", propName);
                else
                    return prop;
            }

            [Category("Data")]
            [Editor(typeof(ComboTextBoxColumnsEditor), typeof(UITypeEditor))]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [Description("Set the columns in showdialog!")]
            public System.Windows.Forms.DataGridViewColumnCollection Columns
            {
                get { return comboTextBox.Columns; }
            }

            [AttributeProvider("System.ComponentModel.IListSource")]
            [Description("选择数据源")]
            [Category("Data")]
            [RefreshProperties(RefreshProperties.All)]
            [DefaultValue(null)]
            public Object DataSource
            {
                get
                {
                    return comboTextBox.DataSource;
                }
                set
                {
                    if (value == null)
                    {
                        DisplayMember = null;
                        ValueMember = null;
                    }
                    GetPropertyByName("DataSource").SetValue(comboTextBox, value);
                    // Refresh the list.
                    this.designerActionUISvc.Refresh(this.Component);
                }
            }

            public String DialogFormName
            {
                get
                {
                    return comboTextBox.DialogFormName;
                }
                set
                {
                    GetPropertyByName("DialogFormName").SetValue(comboTextBox, value);
                }
            }

            [DefaultValue(null)]
            [TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
            [Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
            [Description("选择显示列")]
            [Category("Data")]
            public string DisplayMember
            {
                get { return comboTextBox.DisplayMember; }
                set
                {
                    if (value == "(none)") value = null;
                    GetPropertyByName("DisplayMember").SetValue(comboTextBox, value);
                }
            }

            [Description("选择数值列")]
            [Category("Data")]
            [DefaultValue(null),
            TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
            Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
            public string ValueMember
            {
                get { return comboTextBox.ValueMember; }
                set
                {
                    if (value == "(none)") value = null;
                    GetPropertyByName("ValueMember").SetValue(comboTextBox, value);
                }
            }

            [Description("选择绑定目标")]
            [Bindable(true)]
            [DefaultValue(null)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [Editor("System.Windows.Forms.Design.DataMemberListEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
            public Object SelectedValue
            {
                get { return comboTextBox.SelectedValue; }
                set
                {
                    GetPropertyByName("SelectedValue").SetValue(comboTextBox, value);
                }
            }

            // Implementation of this abstract method creates smart tag 
            // items, associates their targets, and collects into list.
            public override DesignerActionItemCollection GetSortedActionItems()
            {
                DesignerActionItemCollection items = new DesignerActionItemCollection();

                //Define static section header entries.
                items.Add(new DesignerActionHeaderItem("Appearance"));
                items.Add(new DesignerActionHeaderItem("Data"));

                items.Add(new DesignerActionPropertyItem("DialogFormName",
                                 "DialogFormName", "Appearance",
                                 "弹出窗名称."));
                items.Add(new DesignerActionPropertyItem("DataSource",
                                 "DataSource", "Data",
                                 "选择数据源."));
                items.Add(new DesignerActionPropertyItem("ValueMember",
                                 "ValueMember", "Data",
                                 "值字段."));
                items.Add(new DesignerActionPropertyItem("DisplayMember",
                                 "DisplayMember", "Data",
                                 "显示字段."));
                items.Add(new DesignerActionPropertyItem("SelectedValue",
                                 "SelectedValue", "Data",
                                 "绑定字段."));
                items.Add(new DesignerActionPropertyItem("Columns",
                                 "Columns", "Data",
                                 "编辑列."));
                return items;
            }
        }



    以上是代码!
    我应该在斜体字部分怎样设置,才能让设计器中的SelectedValue
    像  combobox /listbox 设计器中的Selected Value一样!
    有字段绑定窗口!

    2009年3月28日 4:44

答案

  • 你好,
    如果你是指ASP.NET SERVER CONTROL,你可以使用下列属性。

    [Bindable(True),Category("Appearance")]
    Winform的不太清楚,你试试看吧。
    Microsoft Online Community Support
    2009年3月31日 6:16