Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 ComboBox
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- List<MobilePhone> mobilePhones = new List<MobilePhone>();
- mobilePhones.Add(new MobilePhone("Nokia", "3310", false, false));
- mobilePhones.Add(new MobilePhone("Samsung", "9100", false, true));
- mobilePhones.Add(new MobilePhone("Fly", "1000", false, true));
- mobilePhones.Add(new MobilePhone("Sony", "Xperia", true, true));
- mobilePhones.Add(new MobilePhone("HTC", "OneX", true, false));
- comboBox1.DataSource = mobilePhones;
- comboBox1.DisplayMember = "Brand";
- listBox1.DataSource = mobilePhones;
- listBox1.DisplayMember = "Brand";
- listBox1.SelectionMode = SelectionMode.MultiExtended;
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- MobilePhone mobilePhone = (MobilePhone)comboBox1.SelectedItem;
- label1.Text = mobilePhone.Model;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string message = "";
- bool isFirstPass = true;
- //foreach (MobilePhone mobilePhone in listBox1.SelectedItems)
- //{
- // if (isFirstPass)
- // message += mobilePhone.Model;
- // else
- // message += " , " + mobilePhone.Model;
- // isFirstPass = false;
- //}
- for (int i = 0; i < listBox1.SelectedItems.Count; i++)
- {
- MobilePhone mobilePhone = (MobilePhone)listBox1.SelectedItems[i];
- if (i == 0)
- message += mobilePhone.Model;
- else
- message += " , " + mobilePhone.Model;
- }
- MessageBox.Show(message);
- }
- }
- public class MobilePhone
- {
- public string Brand { get; set; }
- public bool Camera { get; set; }
- public bool TouchPad { get; set; }
- public string Model { get; set; }
- public MobilePhone(string brand, string model, bool camera, bool touchPad)
- {
- Brand = brand;
- Camera = camera;
- TouchPad = touchPad;
- Model = model;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement