各位前辈: 小弟想做一个容器控件继承Pan控件,增加新属性[相关表],然后想跟据[相关表]自动在容器中创建表中各字段控件.
但以下自动创建代码我不知道写在哪里,在OnCreateControl,OnPaint中,执行时[相关表]为空,就不能创建.
System.Int32 i = 0;
                foreach (System.Data.DataColumn col in this.相关表.Columns)
                {
                    i += 1;
                    ComboBox a = new ComboBox();
                    a.Name = col.ColumnName;
                    a.Location = new System.Drawing.Point(0, i * a.Height);
                    this.Controls.Add(a);
                } 请高手赐教,谢谢!

解决方案 »

  1.   

    放在中InitializeComponent吗?  另外如果【相关表】为空,就不会进入循环,
    也就不会创建啊。
      

  2.   

    使用DataView吧,空也不会出错。
      

  3.   


    private DataTable m_bindtable;public DataTable BindTable
    {
      get{return m_bindtable;}
      set
        {
          m_bindtable = value;
          Bind();
        }
    }System.Int32 i = 0; 
    private void Bind()
    {
                     foreach (System.Data.DataColumn col in this.相关表.Columns) 
                    { 
                        i += 1; 
                        ComboBox a = new ComboBox(); 
                        a.Name = col.ColumnName; 
                        a.Location = new System.Drawing.Point(0, i * a.Height); 
                        this.Controls.Add(a); 
                    } }