[100分求助]:comboBox.SelectedValue 属性设置异常!
## 我有这样一个表:
myID myName
------------------------ -----------------------------
1 aaa
2 bbb
3 ccc
## 在VS2003中,我的代码如下:
//
// step 1: 读取上面的表并fill到一个dataset中
//
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(...);
da.Fill(ds, "table1");
//
// step 2: 在该表的开头插入一条记录
//
DataRow dr = ds.Tables["table1"].NewRow();
dr["myID"] = "0";
dr["myName"] = "<all>";
ds.Tables["table1"].Rows.InsertAt(dr, 0);
ds.Tables["table1"].AcceptChanges();
//
// step 3: 把其绑定到comboBox1
//
comboBox1.DataSource = ds.Tables["table1"];
comboBox1.DisplayMember = "myName";
comboBox1.ValueMember = "myID";
## 所有运行正常,comboBox1出现绑定表中的记录(包括新插入的那条).
## 但当我运行:
comboBox1.SelectedValue = 1; //error
## 时,出现异常。
## 我改为:
comboBox1.SelectedValue = 2; //no error
## 时,没有任何错误。
## 另外当我跳过step 2并运行"comboBox1.SelectedValue = 1;"时,也没有错误出现。
## 那么step 2到底有什么错呢?
(请不要建议我在“数据库”表中添加"0"-"<all>"的方法!)