You need to create the Workshop class and the Location class. Something like this:
Then you create lists of the workshops and locations:Code:class Workshop { public string Name { get; set; } // or public int ID to use it as a key public decimal RegistrationFee { get; set; } public int Days { get; set; } public Workshop(string name, decimal registrationFee, int days) { ... } } class Location { public string Name { get; set; } public decimal LodgingFee { get; set; } public Location(string name, decimal lodgingFee) { ... } }
Then you set these lists to your listboxes' datasources and set DisplayMember:Code:var workshops = new List<Workshop>() { new Workshop("Bla bla", 100, 20), new Workshop("Muahaha", 10, 10) }; var locations = new List<Location>() { new Location("My super location 1", 10), new Location("My super location 2", 20), }
When you need to get selected workshop and location you write this:Code:lbWorkshops.DataSource = workshops; lbWorkshops.DisplayMember = "Name"; // note this, it will use Name property to display it in the listbox lbLocations.DataSource = locations; lbLocations.DisplayMember = "Name";
I wrote this code in the browser and didn't test it.Code:var workshop = (Workshop)lbWorkshops.SelectedItem; var location = (Location)lbLocations.SelectedItem; // now you can get the necessary properties: decimal workshopRegFee = workshop.RegistrationFee; decimal locationLodgingFee = location.LodgingFee;




Reply With Quote