wpf combobox 的使用

来源:互联网 发布:顶管计算软件 编辑:程序博客网 时间:2024/05/07 16:55
IList<his_nation> customList = new List<his_nation>();
        public Window1()        {            InitializeComponent();            BindCombobox();        }

初始化


        public void BindCombobox()        {            IList<String> NationstrList = new List<String>();            NationstrList.Add("汉族");            NationstrList.Add("壮族");            NationstrList.Add("Cat");            String str = NationstrList[0];            customList.Add(new nation() { ID = 1, Name = "汉族" });            customList.Add(new nation() { ID = 2, Name = "壮族" });            customList.Add(new nation() { ID = 3, Name = "Cat" });            cbb_nation.ItemsSource = customList;            cbb_nation.DisplayMemberPath = "Name";            cbb_nation.SelectedValuePath = "ID";            cbb_nation.SelectedValue = 1;        }public class his_nation{    public int ID {         get;         set;    }    public string Name {         get;         set;    }}


获取combobox选中的值

          int tt =  cbb_nation.SelectedIndex;
          String name =  customList[tt].Name;



原创粉丝点击