winform的combox下拉框绑定数据源

            List list = new List();

            foreach (DataRow srcDr in srcDt.Rows)
            {
                list.Add(new Site { Text = srcDr["SiteName"].ToString(), Value = (int)srcDr["SiteId"],Identifier = srcDr["identifier"].ToString() });
            }

            CboSite.DisplayMember = "Text";
            CboSite.ValueMember = "Value";
            CboSite.Tag = "Identifier";
            CboSite.DataSource = list;
    public class Site
    {
        public int Value { get; set; }
        public string Text { get; set; }
        public string Identifier { get; set; }
    }

 

((Site)CboSite.SelectedItem).Identifier;

 

转载于:https://www.cnblogs.com/maijin/p/6738566.html

你可能感兴趣的:(winform的combox下拉框绑定数据源)