展开全部
已测试过,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;
label1.Text = aText;
}
}
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;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询