【问题标题】:How to make editable objects in the designers `Collection Editor Windows`?如何在设计师的“收藏编辑器窗口”中制作可编辑的对象?
【发布时间】:2021-04-11 06:26:43
【问题描述】:

我创建了一个从 TDataSet 派生的自定义组件。
现在我从名为gttTables 的自定义类型dsTable 创建了一个集合。 (所有代码都在下面)

当我将组件放在表单上时,集合 gttTables 会显示在 property window 中,当我单击 3dotted 按钮时,Collection Editor Windows 会按预期显示。
Collection Editor Windows 中,我可以单击Add,这将在窗口中添加一个新项目,该项目似乎是我预期的dsTable 类型。

现在解决问题。
Collection Editor Windows 中,我无法查看/更改左侧列表中每个dsTable 的任何属性。右侧只显示Value,值为gttControls.dsTable
让我告诉你我对这张照片的意思

我想在这里查看添加到Collection Editor Windows 中的每个dsTable 的属性,以便我可以编辑它们。

这是我的完整代码。
我的问题是我应该怎么做才能编辑Collection Editor Windows 中每个添加的dsTable 的属性?

public partial class gttDataSet : DataSet
{
    Collection<dsTable> _dsTables = new Collection<dsTable>();

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor("System.ComponentModel.Design.CollectionEditor, System.Design", typeof(UITypeEditor))]
    [Category("GTT")]
    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    public Collection<dsTable> gttTables
    {
        get { return _dsTables; }
        set { _dsTables = value; }
    }
}

public class dsTable
{
    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    string SelectText { get; set; }

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    string SelectTextForUpdate { get; set; }

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    string DesignWhereText { get; set; }

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    string UserWhereText { get; set; }

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    bool IsStoredProcedure { get; set; }

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    bool RetrieveColumns { get;  }
}

编辑
我查看了How do you create a custom collection editor form for use with the property grid?,虽然它包含有用的信息,但在我的情况下似乎没有必要。 @Serg 的回答解决了我的问题

【问题讨论】:

标签: c# visual-studio winforms visual-studio-2015 custom-controls


【解决方案1】:

您应该使您的dsTable 类属性public 能够使用PropertyGrid 编辑这些属性

public class dsTable
{
    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    public string SelectText { get; set; } // <--- changed here

    //make the same changes for other properties you want to edit.
}

【讨论】:

  • 天哪,这么简单,我怎么看不到这个。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多