privatevoid comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//check if the item exists already and only add if it doesn't
if (listBox1.Items.IndexOf(comboBox1.SelectedItem.ToString()) == -1)
{
listBox1.Items.Add(comboBox1.SelectedItem.ToString());
}
}
评论会员:巴拉Selvanayagam 时间:2012/02/06
这里LAMDA表达式版本
if ((listBox1.Items.Cast<string>().ToList())
.Where(c => c == textBox1.Text).Count() == 0)
listBox1.Items.Add(textBox1.Text);
</string>