Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C# I am trying to display data from two listboxes in a new form. How do I combine both If in the private void

In C# I am trying to display data from two listboxes in a new form.

How do I combine both If in the private void calculateButton_Click(object sender, EventArgs e)

so it whould only open 1 new form with the data from both listboxes listed?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace DormAndMealPlanCalculator { public partial class MainForm : Form { List LocationList; List MealList; public MainForm() { InitializeComponent();

Dorm locationInfo;

LocationList = new List();

LocationList.Add(locationInfo = new Dorm("Allen Hall", 1500)); dormListBox.Items.Add(locationInfo.Location);

LocationList.Add(locationInfo = new Dorm("Pike Hall", 1600)); dormListBox.Items.Add(locationInfo.Location);

LocationList.Add(locationInfo = new Dorm("Farthing Hall", 1800)); dormListBox.Items.Add(locationInfo.Location);

LocationList.Add(locationInfo = new Dorm("University Suites", 2500)); dormListBox.Items.Add(locationInfo.Location);

Meal mealInfo;

MealList = new List();

MealList.Add(mealInfo = new Meal("7 meals per week", 600)); mealListBox.Items.Add(mealInfo.MealOptions);

MealList.Add(mealInfo = new Meal("14 meals per week", 1200)); mealListBox.Items.Add(mealInfo.MealOptions);

MealList.Add(mealInfo = new Meal("Unlimited meals", 1700)); mealListBox.Items.Add(mealInfo.MealOptions);

}

private void calculateButton_Click(object sender, EventArgs e) { if (dormListBox.SelectedIndex != -1) { var viewInfo = new TotalChargesForm(LocationList[dormListBox.SelectedIndex]).ShowDialog(); } if (mealListBox.SelectedIndex != -1) { var viewInfo = new TotalChargesForm(MealList[mealListBox.SelectedIndex]).ShowDialog(); } }

private void exitButton_Click(object sender, EventArgs e) { // Close the form. this.Close(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions