Background
I have a Windows Form with the following items
ComboBoxTextBox- Two
Buttons: Forward and Back A class -
Itemswhich holds astringintanddoublemembersif (ComboBox1.SelectedIndex == 2 && Items[index].Price > 50.00 ) { txtManu.Text = Items[index].Manu; txtPrice.Text = Convert.ToString(Items[index].Price); }
When I click the forward button on the form I expect all prices over 50.00 to be displayed in the txtPrice.Text TextBox but it's displaying all prices instead.
Forward button code snippet:
else if (comboBox1.SelectedIndex == 2 && Items[index].Price > 50.00)
{
index += 1;
if (index == Items.Length) index = 0;
txtManu.Text = Items[index].Manu;
}
The ComboBox has index[0] and index[1] items: ComboBox1.SelectedIndex == 0 and ComboBox1.SelectedIndex == 1.
The forward button has index 0 and index 1 items too: if (comboBox1.SelectedIndex == 0) and if (comboBox1.SelectedIndex == 1)
Why isn't the if statement not executing?
Update
Here is the improved code for the example:
Items[0] = new items("Car", 30.00); Items[1] = new itemss("Cat", 55.00); Items[2] = new items("Cookie", 59.00);
ComboBox Code Snippet
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);