• winform下自带的Combox 绑定数据源 样例


       public static void SetComboList(ComboBox cboSource, string sSQL,string sWindowTxt,string sFirstItem="",int iFirstItemValue=-1,DataTable dtSource=null)
           {
               string sError = string.Empty;
               DataTable dt=null;
    
               if (!string.IsNullOrEmpty(sSQL))
               {
                   dt = SqlLiteHelper.GetDataTable(out sError, sSQL);
                   if (!string.IsNullOrEmpty(sError))
                       Common.DisplayMsg(sWindowTxt, sError);
               }
               else if (dtSource != null)
               {
                   dt = dtSource.Copy();
               }
    
               if (!string.IsNullOrEmpty(sFirstItem))
               {
                   DataRow dr = dt.NewRow();
                   dr[0] = iFirstItemValue;
                   dr[1] = sFirstItem;
    
                   dt.Rows.InsertAt(dr, 0);
               }
    
               //cboSource.Items.Clear();
    
               cboSource.DataSource = dt;
               cboSource.ValueMember = dt.Columns[0].ColumnName;
               cboSource.DisplayMember = dt.Columns[1].ColumnName;
               cboSource.DropDownStyle = ComboBoxStyle.DropDownList;
           }


    调用方法:

            private void InitOutputType()
            {
                string sSql = "select * from tgExpenditureItem";
                Common.SetComboList(cboOutputItem, sSql, this.Text);
            }

  • 相关阅读:
    ltp-ddt makefile的思考
    Linux configure,make,make install
    linux下can调试工具canutils安装过程记录
    windows下运行jar
    悲观锁
    mysql事务锁表
    静态内部类
    局部类
    匿名内部类(new类时覆盖类中方法)
    回文字
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3033496.html
Copyright © 2020-2023  润新知