请指点,以下那里出现错误,会出现死循环,
string seat1_val=this.textBox5.Text.Trim()+'/'+this.textBox9.Text.Trim();
for(int i=0;i<=this.comboBox3.Items.Count;i++)
{
if(this.comboBox3.Items[i].ToString()==seat1_val)
{
MessageBox.Show("有相同的属性值");
}
else
{
this.comboBox3.Items.Add(seat1_val);
MessageBox.Show("添加完成!");
}
}
string seat1_val=this.textBox5.Text.Trim()+'/'+this.textBox9.Text.Trim();
for(int i=0;i<=this.comboBox3.Items.Count;i++)
{
if(this.comboBox3.Items[i].ToString()==seat1_val)
{
MessageBox.Show("有相同的属性值");
}
else
{
this.comboBox3.Items.Add(seat1_val);
MessageBox.Show("添加完成!");
}
}
this.comboBox3.Items.Count也增加一
在添加之后,用break跳出循环
应该是
bool bSame = false;
for ()
{
if (==)
{
bSame = true;
break;
}
}
if (bSame == false)
{
combobox.items.add();
}
string seat1_val=this.textBox5.Text.Trim()+'/'+this.textBox9.Text.Trim();
if (this.comboBox3.Items.Contains(seat1_val))
{
MessageBox.Show("有相同的属性值");
}
else
{
this.comboBox3.Items.Add(seat1_val);
MessageBox.Show("添加完成!");
}