wpf ComboBox控件DisplayMemberPath属性怎么绑定多值?从数据库绑定

怎么在ComboBox控件上显示两个值,就是把name、id都显示出来
2024-12-14 05:53:38
推荐回答(1个)
回答1:

ds = new DataSet();
DBHelper dbHelper = new DBHelper();
// 查询歌曲类型的Sql语句
string sql = "select * from song_type";
SqlDataAdapter adapter = new SqlDataAdapter(sql, dbHelper.Connection);
adapter.Fill(ds, "song_type");

// 绑定歌曲类型到下拉列表中
this.cboSongType.DataSource = ds.Tables["song_type"];
this.cboSongType.ValueMember = "songtype_id";
this.cboSongType.DisplayMember = "songtype_name";