2个回答
展开全部
测试了一下,应该OK,望采纳。
private void Form1_Load(object sender, EventArgs e)
{
var aList = ComboBoxItem.GetList();
comboBox1.DataSource = aList;
comboBox1.DisplayMember = "Text";
comboBox1.ValueMember = "Value";
var aComboBoxItem = comboBox1.SelectedItem as ComboBoxItem;
if (aComboBoxItem != null)
{
var aValue = aComboBoxItem.Value;
var aText = aComboBoxItem.Text;
}
}
private class ComboBoxItem
{
public string Value { get; set; }
public string Text { get; set; }
public static List<ComboBoxItem> GetList()
{
var aList = new List<ComboBoxItem>();
for (int i = 0; i < 10; i++)
{
var aComboBoxItem = new ComboBoxItem();
aComboBoxItem.Text = string.Format("Text_{0}", i);
aComboBoxItem.Value = string.Format("Value_{0}", i);
aList.Add(aComboBoxItem);
}
return aList;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询