本帖最后由 chaidaxia 于 2012-12-31 20:46:22 编辑

解决方案 »

  1.   

    贴出你自定义的ComboBox代码以及如果将自定义控件加入Form的代码
      

  2.   

    按照下面的定义以及添加到Form中去没有问题,本机测试过using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;namespace TestWinForm
    {
        public class MyComboBox : ComboBox
        {
            public MyComboBox()
            {
                string connectionStr =
                    @"Data Source=XXX\SQLEXPRESS;Initial Catalog=XXX;Integrated Security=True";
                object result = null;
                using (SqlConnection conn = new SqlConnection(connectionStr))
                {
                    SqlCommand com = new SqlCommand("SELECT PersonID FROM Person ORDER BY PersonID DESC", conn);
                    com.Connection.Open();
                    result = com.ExecuteScalar();
                }
                this.Items.Add(result);
                this.Items.Add(1);
                this.Items.Add(2);
            }
        }
    }this.Controls.Add(new MyComboBox());