日期:2014-05-19  浏览次数:20964 次

c#中的combobox绑定问题
我把combobox绑定到了一个数据源,并想把combobox的值插入数据库

DataSet   ds   =   new   DataSet();
adapter1.Fill(ds,   "table1 ");
comboBox1.DisplayMember   =   "vdescription ";
comboBox1.ValueMember   =   "ccodeID ";
comboBox1.DataSource   =   ds.Tables[ "table1 "];

但是combobox始终显示数据源的第一条记录,有什么办法能让combobox默认值显示空或者显示“-请选择-”之类的词,然后同时能以空值插入数据库呢?

------解决方案--------------------
try

DataSet ds = new DataSet();
adapter1.Fill(ds, "table1 ");
DataRow dr = ds.Tables[ "table1 "].NewRow();
dr[ "ccodeID "] = "00 ";
dr[ "vdescription "] = "-请选择- ";
ds.Tables[ "table1 "].Rows.InsertAt(dr, 0);
comboBox1.DisplayMember = "vdescription ";
comboBox1.ValueMember = "ccodeID ";
comboBox1.DataSource = ds.Tables[ "table1 "];