手工设置Item可以添加Index为0的item;
绑定数据源的话就需要从数据源上操作:
DataRow dr = dt.NewRow();
dr["id"] = "全部";// 显示全部或空
dr["name"] = "";
dt.Rows.InsertAt(dr, 0);
this.comboBox1.DataSource = dt;
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = 0; //默认显示
本文介绍了一种在C#中通过手工设置或绑定数据源来为组合框ComboBox添加默认选项的方法。具体步骤包括创建新的数据行、插入指定的行到数据表的特定位置,并将数据表设置为ComboBox的数据源。
手工设置Item可以添加Index为0的item;
绑定数据源的话就需要从数据源上操作:
DataRow dr = dt.NewRow();
dr["id"] = "全部";// 显示全部或空
dr["name"] = "";
dt.Rows.InsertAt(dr, 0);
this.comboBox1.DataSource = dt;
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = 0; //默认显示
4445

被折叠的 条评论
为什么被折叠?