C#

C# IF ListBox Arrays 2D Arrays Read File Example 1 Example Midterm 1 Example Midterm 2 Example 5 Example 7 Group Project 2 Example 9 Group Project 2
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

C# : ListBox

2017-01-01

ListBox

//deselect
listBox_pizza.SelectedIndex = -1;

//add 1 item
lb_orderQuantity.Items.Add(listBox_salad.SelectedItem);

// remove item
lb_orderQuantity.Items.Remove(lb_orderQuantity.SelectedItem);

// remove all items
listBox1.Items.Clear();

//if not selected
if (lb_orderQuantity.SelectedIndex != -1)
{
    // selected
}

//loop through all items
subtotal = 0;
foreach (var listBoxItem in lb_orderQuantity.Items)
{
    string item = listBoxItem.ToString().Substring(0, 3);
    switch (item)
    {
        case "Pep": subtotal = subtotal + PEPPERONI_PIZZA_PRICE; break;
        case "Mus": subtotal = subtotal + MUSHROOM_PIZZA_PRICE;  break;
        case "Gar": subtotal = subtotal + GARDEN_SALAD_PRICE;  break;
        case "Cae": subtotal = subtotal + CASEAR_SALAD_PRICE;  break;
    }
}