你好!
这需要做一个转换。
比如绑定的是一个 DataTable, SelectItem 对应的是 DataRowView。
如:
this.combobox.DisplayMember = "Name";
this.combobox.ValueMember = "Id";
this.combobox.DataSource = this.dt;
...
取值
if (this.combobox.SelectedItem == null)
return;
DataRowView drv = this.combobox.SelectedItem as DataRowView; // 将 SelectItem 转换为 DataRowView
MessageBox.Show(string.Format("Id:{0}\r\nName:{1}", drv["Id"], drv["Name"]));
若数据源是 List<T> 则 SelectItem 对应的类型为 T。
知识改变命运,奋斗成就人生!