/// <summary> /// ����һ�е�ComboList /// </summary> /// <param name="c1FlexGrid1">���</param> /// <param name="GridCol">Grid��������</param> /// <param name="ValueCol">����</param> /// <param name="DisplayCol">��ʾ������</param> /// <param name="table">������</param> /// <param name="sqlString">sql���</param> /// <param name="FromText">�����textֵ</param> public static void SetColumnComboList(C1.Win.C1FlexGrid.C1FlexGrid c1FlexGrid1,string GridCol, string ValueCol, string DisplayCol, string table, string sqlString,string FromText) { ComboListAndDataMap cd = new ComboListAndDataMap(); cd = GetComboListData(GridCol, ValueCol, DisplayCol, table, sqlString, FromText); if (cd == null) return; //c1FlexGrid1.Cols[GridCol].ComboList = cd.comboString; c1FlexGrid1.Cols[GridCol].DataMap = cd.dataMap; }
private static ComboListAndDataMap GetComboListData(string GridCol, string ValueCol, string DisplayCol, string table, string sqlString, string FromText) { ComboListAndDataMap cd = new ComboListAndDataMap(); try { System.Text.StringBuilder sbList = new System.Text.StringBuilder(); SortedList dMap = new SortedList(); //Hashtable dMap = new Hashtable(); /*DataSet ds_var = new DataSet(); DBUtility.SQLExecute.Fill(sqlString, ds_var, table); using (System.Data.DataTable dt = ds_var.Tables[table]) { foreach (DataRow dr in dt.Rows) { string strName = ""; strName = dr[DisplayCol].ToString(); sbList.Append(strName + "|"); dMap.Add(dr[ValueCol], strName); } }*/ using (System.Data.Common.DbDataReader reader = Main.SQLExecute.ExecuteReader(sqlString)) { //sbList.Append("|"); while (reader.Read()) { string strName = ""; strName = reader[DisplayCol].ToString(); sbList.Append(strName + "|"); dMap.Add(reader[ValueCol], strName); } reader.Close(); } string strListTo = sbList.ToString(); if (strListTo.Length > 1) strListTo = strListTo.Substring(0, strListTo.Length - 1); cd.comboString = strListTo; cd.dataMap = dMap; } catch (Exception ex) { MessageBox.Show(ex.Message, FromText, MessageBoxButtons.OK, MessageBoxIcon.Error); } return cd; }