for (int i = 0; i < this.ListBox1.Items.Count; i++)
{
if (this.ListBox1.Items[i].Selected == true)
{
if (this.ListBox2.Items.Count == 0) { this.ListBox2.Items.Add(ListBox1.Items[i]); } // listbox2中没有数据
else
{
for (int j = 0; j < this.ListBox2.Items.Count; j++)
{
//listbox中是否已存在
if (ListBox2.Items[j].Text.ToString().Equals(ListBox1.Items[i].Text.ToString()))
{
break; //跳出本次循环
}
if (j == this.ListBox2.Items.Count - 1) //不存在
{
this.ListBox2.Items.Add(this.ListBox1.Items[i]); //选中项写入listbox2中
this.ListBox2.Items[ListBox2.Items.Count - 1].Selected = false;
}
}
}
}
}
{
if (this.ListBox1.Items[i].Selected == true)
{
if (this.ListBox2.Items.Count == 0) { this.ListBox2.Items.Add(ListBox1.Items[i]); } // listbox2中没有数据
else
{
for (int j = 0; j < this.ListBox2.Items.Count; j++)
{
//listbox中是否已存在
if (ListBox2.Items[j].Text.ToString().Equals(ListBox1.Items[i].Text.ToString()))
{
break; //跳出本次循环
}
if (j == this.ListBox2.Items.Count - 1) //不存在
{
this.ListBox2.Items.Add(this.ListBox1.Items[i]); //选中项写入listbox2中
this.ListBox2.Items[ListBox2.Items.Count - 1].Selected = false;
}
}
}
}
}