Фон
У меня есть форма Windows со следующими элементами:
ComboBox
TextBox
- Два
Buttons
: вперед и назад
- A класс -
Items
, который содержит string
int
и double
членов
if (ComboBox1.SelectedIndex == 2 && Items[index].Price > 50.00 )
{
txtManu.Text = Items[index].Manu;
txtPrice.Text = Convert.ToString(Items[index].Price);
}
Когда я нажимаю кнопку forward
в форме, я ожидаю, что все цены за 50.00
будут отображаться в текстовом поле txtPrice.Text
, но вместо этого отображаются все цены.
Фрагмент кода кнопки «Вперед»:
else if (comboBox1.SelectedIndex == 2 && Items[index].Price > 50.00)
{
index += 1;
if (index == Items.Length) index = 0;
txtManu.Text = Items[index].Manu;
}
У ComboBox
есть index[0]
и index[1]
предметов: ComboBox1.SelectedIndex == 0
и ComboBox1.SelectedIndex == 1
.
Кнопка «Вперед» также имеет индекс 0 и индекс 1: if (comboBox1.SelectedIndex == 0)
и if (comboBox1.SelectedIndex == 1)
Почему оператор if
не выполняется?
Обновление
Вот улучшенный код для примера:
Items[0] = new items("Car", 30.00);
Items[1] = new itemss("Cat", 55.00);
Items[2] = new items("Cookie", 59.00);
Фрагмент кода ComboBox
if (ComboBox1.SelectedIndex == 0 && Items[index].Price > 50.00 )
{
txtPrice.Text = Convert.ToString(Items[index].Price);
}
###Forward Button
//single combobox
if (comboBox1.SelectedIndex == 2 && Items[index].Price > 50.00)
{
index += 1;
}
if (index == Items.Length)
{
index = 0;
}
txtPrice.Text = Convert.ToString(Items[index].Price);