ComboBox DisplatMember显示Code和Name的方法

private void ShopList(Dictionary<string, ShopInfo> shopLists, ComboBox comboBox, string shopCode)
{
if ((shopLists != null) && (shopLists.Count != 0))
{
var item = new ListItem("", "");
var listItem = new List<ListItem>();
listItem.Add(item);
foreach (ShopInfo info in shopLists.Values)
{
item = new ListItem(info.CODE.Trim(), "[" + info.CODE.Trim() + "] " + info.FULLNAME);
listItem.Add(item);
}
comboBox.DisplayMember = "Name";
comboBox.ValueMember = "Code";
comboBox.DataSource = listItem;
if (!string.IsNullOrEmpty(shopCode))
{
comboBox.SelectedValue = shopCode;
}
else
{
comboBox.SelectedIndex = 0;
}
}
}

posted @ 2013-03-16 15:39  dotNet修行之路  阅读(332)  评论(0编辑  收藏  举报