开发者

Edit DataGridView via Designer in inherited UserControl

开发者 https://www.devze.com 2023-01-24 13:43 出处:网络
I created a UserControl with a Button, a TextBox and a DataGridView. I set the modifiers of all controls to public.

I created a UserControl with a Button, a TextBox and a DataGridView. I set the modifiers of all controls to public.

Now If I inherit from that UserControl, I can modify the TextBox and the Button via Designer (move around, change properties) just as I expected. But for the DataGridView all properties are disabled.

Is there any reason, why I can't modify a DataGridView via the Designer in an inh开发者_开发百科erited UserControl?


Found a solution here: http://adamhouldsworth.blogspot.com/2010/02/winforms-visual-inheritance-limitations.html

In short:

  1. Add a reference to System.Design
  2. Inherit from DataGridView with this code:

    [Designer(typeof(ControlDesigner))]
    public class InheritableDataGridView : DataGridView
    {
        public InheritableDataGridView()
            : base()
        { }
    }
    
  3. ???
  4. Profit!!!
0

精彩评论

暂无评论...
验证码 换一张
取 消