如何在ComboBox中添加‘please select’项?

内容纲要

如果ComboBox是非绑定,我们可以直接添加一项到ComboBox的项集合中。

代码:

this.comboBox1.Items.Insert(0, "please select");

this.comboBox1.SelectedIndex = 0;

如果ComboBox是数据绑定的,我们就需要将这一项添加到数据源中。

代码:

Customer cust = new Customer("Joe", null);

DataRow row = statesTable.NewRow();

row["Name"] = " please select";

row["Code"] = DBNull.Value;

statesTable.Rows.Add(row);

this.statesCB.DisplayMember = "Name";

this.statesCB.ValueMember = "Code";

this.statesCB.DataSource = statesTable;

this.statesCB.DataBindings.Add("SelectedValue", cust, "StateID", true);

圈主 管理员

热门评论
:
该帖子评论已关闭
图片审查中...
编辑答案: 我的回答: 最多上传一张图片和一个附件
x
x
个人中心
今日签到
有新私信 私信列表
搜索