combobox 的 datasource 一般是查询存储过程得到 , 但在测试或演示时,也可以自己定义 , 方法是 :
DataTable customerTable = new DataTable();
customerTable.Columns.Add("clsCustomerID", typeof(string)); //定义列类型
customerTable.Columns.Add("clsCustomerNM", typeof(string));DataRow row = customerTable.NewRow(); //加一行
row["clsCustomerID"] = "01.2136";
row["clsCustomerNM"] = "MAXIS1";customerTable.Rows.Add(row);
DataRow row1 = customerTable.NewRow(); //加另一行
row1["clsCustomerID"] = "01.2255";
row1["clsCustomerNM"] = "VSC2_PRE_W1";customerTable.Rows.Add(row1);
comboBox1.DataSource = customerTable; //设置datasource 和 显示和实际数据列
comboBox1.DisplayMember = "clsCustomerNM";
comboBox1.ValueMember = "clsCustomerID";
自定义data table 的列类型,并填充数据
时间: 2024-10-29 10:39:34