C# .net 4.6 DataGridView as Property of custom Component

300 views Asked by At

I'm currently working on an MultiColumnComboBox which contains an DataGridView as DropDownControl. I've found https://www.codeproject.com/Articles/25471/Customizable-ComboBox-Drop-Down and used it as Parentclass.

Here is the important Part of the Code.

namespace GUILib
{
    partial class MultiColumnDropDown
    {

        ...

        [
            Browsable(true),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))
        ]
        public System.Windows.Forms.DataGridView datagrid
        {
            get
            {
                return dataGridView1;
            }
            set
            {
                dataGridView1 = value;
            }
        }

        ...

        #region Vom Komponenten-Designer generierter Code

        ///  
        /// Erforderliche Methode für die Designerunterstützung. 
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// 
        private void InitializeComponent()
        {
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGridView1
            // 
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Location = new System.Drawing.Point(0, 0);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(240, 150);
            this.dataGridView1.TabIndex = 0;
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.DataGridView dataGridView1;
    }
}

My Problem is when I add this custom Control to a Form I can change every Property of datagrid except Columns. When I try to modify Columns by clicking on the Button with the three dots i'll get an error:

Error

Translated it is "Object reference not set to an instance to an object". If i'll add Columns in the code (multiColumnDropDown1.datagrid.Columns.Add) the Columns are added at runtime.

Can someone tell me where i've made an Error?

Greetings Michael

P.S. Sorry for my bad english, i'll hope someone understand what i mean and can help me.

0

There are 0 answers