string[] BWnames = new string[] { "大大", "三三", "王王", "七七", "其它" };
List
for (int i = 0; i < BWnames.Length; i++)
{
zxxxtypeZD xmmc = new zxxxtypeZD()
{
gcid = cgcid.ToString(),
xxzxmtyname = BWnames[i]
};
gcbws.Add(xmmc);
}
//月份下拉列表
this.cobx_month.DataSource = gcbws;
this.cobx_month.DisplayMember = "monthname";
this.cobx_month.ValueMember = "monthid";
if (cobx_month.Items.Count > 0)
{
this.cobx_month.SelectedValue= currentmonth;//默认分类
}
===========================方法二
//首先声明表格
DataTable dataTable = new DataTable();
/// 添加列:
dataTable.Columns.Add("xxzxmtyid");
dataTable.Columns.Add("xxzxmtyname");
// 添加数据:
for (int i = 0; i < BWnames.Length; i++)
{
DataRow dr = dataTable.NewRow();
dr["xxzxmtyid"] = i;
dr["xxzxmtyname"] = BWnames[i];
// dr["xxzxmtyid"] = gc;
dataTable.Rows.Add(dr);
}
//绑定数据源
cbox_type.DataSource = dataTable;
this.cbox_type.DisplayMember = "xxzxmtyname";
this.cbox_type.ValueMember = "xxzxmtyid";