Question

I have a piece of code something like below. I'm using Microsoft Visual C# Express Edition. My problem is that I can't add columns to a DataGridView in design-time which is a member of another class. Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClassLibrary1
{
    public class Class1 : Panel
    {
        DataGridView mView;

        public Class1()
        {
        mView = new DataGridView();
        this.Controls.Add(mView);
        }

        public DataGridView View
        {
            get { return mView; }
            set { mView = value; }
        }
    }
}

When I click the three dotted button to add new columns in properties window i got System.NullException in design-time. I couldn't post the screenshot because of my reputation.

Thanks for help!

Was it helpful?

Solution

I just a deeper look into your question. Unfortunatelly I was able to reproduce the described matter. After some research in DataGridView in usercontrols i thumbled over the following post.

It seems that there is no visual support for an inherited DataGridView - and - not for userControls using DataGridView, too. You may also have a look at this article

I tried using the following inherited DataGridView classes - but neither worked. I am sorry for not having a proper solution - but I hope this may be of any use for you.

/// tried this attribute - did not work
/// [Designer(typeof (System.Windows.Forms.Design.ControlDesigner))]

/// this did not work either
[Editor("System.Windows.Forms.Design.DataGridViewComponentEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(ComponentEditor))]
[Designer("System.Windows.Forms.Design.DataGridViewDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ucInheritedDataGridView : DataGridView { }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top