一:根据数据源类型获取选中项
类:
public class Region { public int REGION_ID { get; set; } public string REGION_CODE { get; set; } public string REGION_NAME { get; set; } public int PARENT_ID { get; set; } }
数据源绑定:
//绑定国家 cbe_Nationality.ItemsSource = new List<Region>() { new Region() { REGION_ID=1, REGION_NAME="中国"}, new Region() { REGION_ID=2, REGION_NAME="美国"} }; cbe_Nationality.SelectedValuePath = "REGION_ID"; cbe_Nationality.DisplayMemberPath = "REGION_NAME"; this.cbe_Nationality.SelectedIndex = 0;
获取选中项 并 取出其中的文本显示内容:
//获取绑定信息 Region cbi = (this.cbe_Nationality.SelectedItem) as Region;
获取了选中项并转换成对象,就可以获取里面的值及文本了