影子博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

public partial class BanCiCombox : UserControl
{
string _gong = "";
Ctrl cl = new Ctrl();
public BanCiCombox()
{
InitializeComponent();
}

    public BanCiCombox(string gong)
    {
        InitializeComponent();
      
        _gong = gong;
        //DataTable dt = new DataTable();

        //dt = cl.GetBanCi(gong);
        //comboBox1.Items.Clear();
        //comboBox1.Items.Add("");
        //for (int i = 0; i < dt.Rows.Count; i++)
        //{
        //    comboBox1.Items.Add(dt.Rows[i]["classcode"].ToString() + "-" + dt.Rows[i]["name"].ToString());
        //} 
    }
    public string Gong { get { return _gong; } set { _gong = value; } }
 
   private void BanCiCombox_Load(object sender, EventArgs e)
    {
        

        DataTable dt = new DataTable();

        dt = cl.GetBanCi(Gong);
        comboBox1.Items.Clear();
        comboBox1.Items.Add("");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            comboBox1.Items.Add(dt.Rows[i]["classcode"].ToString()+"-"+dt.Rows[i]["name"].ToString());
        } 

    }

   public override string Text
   {
       get
       {
           string value = "";

           if (comboBox1.Text.IndexOf("-") > 0)
           {
               value = comboBox1.Text.Substring(0, comboBox1.Text.IndexOf("-"));
           }
           else
           {
               value = comboBox1.Text.Trim();
           }

           //if (comboBox1.Text.Trim()!="")value =comboBox1.Text.Substring(0, comboBox1.Text.IndexOf("-"));
           return value;
       }

       set { comboBox1.Text = value; }

   }
   public  int  SelectedIndex
   {

       get
       {
       
           return comboBox1.SelectedIndex;
       }

       set { comboBox1.SelectedIndex = value; }


   }
    public delegate void UserHandler(object sender,System.EventArgs e);
    //public event UserHandler SelectedIndexChanged;//如果要将事件帮定到控件里面的事件则
 //   private void cboDataBase_SelectedIndexChanged(object sender, System.EventArgs e)  {   OnDBSChanged(sender,e);  }
   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //SelectedIndexChanged(sender, e);
        
   }


}
posted on 2016-07-07 14:53  影子博客  阅读(113)  评论(0编辑  收藏  举报