DataGridView下的DataGridViewComboBoxCell 显示与绑定下拉值

  //DataGridView绑定查询的数据脚本
  string sql = @"select CASE WHA_State when 1 THEN '启用'  When 2 Then '暂停' when 3 Then '停止'  End as WHA_State ,* from WHA_WarehouseArea where 1=1";

//DataGridViewComboBoxCell 绑定下拉项的脚本
string sqlcom = @"select distinct CASE WHA_State when 1 THEN '启用'  When 2 Then '暂停' when 3  Then '停止'   End as WHA_State  from WHA_WarehouseArea where 1=1";
      
       //DataGridView绑定数据
                DataSet ds = GlobalData.Instance.dbManager.ExecuteDataSet(sql);
                dGFactoryList.DataSource = ds.Tables[0];
       DataTable dt=GlobalData.Instance.dbManager.GetDataTableBySql(sqlcom);

  //DataGridViewComboBoxCell 添加下拉框选项
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {                ((DataGridViewComboBoxCell)dGFactoryList.Rows[i].Cells["WHA_State"]).DataSource = dt;                   ((DataGridViewComboBoxCell)dGFactoryList.Rows[i].Cells["WHA_State"]).DisplayMember = "WHA_State";               ((DataGridViewComboBoxCell)dGFactoryList.Rows[i].Cells["WHA_State"]).ValueMember = "WHA_State";
                }

版权声明:本文为Wesley_xiaoyi原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。