Advertisement
aslen

Untitled

May 6th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace ComboBox
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.             List<MobilePhone> mobilePhones = new List<MobilePhone>();
  23.             mobilePhones.Add(new MobilePhone("Nokia", "3310", false, false));
  24.             mobilePhones.Add(new MobilePhone("Samsung", "9100", false, true));
  25.             mobilePhones.Add(new MobilePhone("Fly", "1000", false, true));
  26.             mobilePhones.Add(new MobilePhone("Sony", "Xperia", true, true));
  27.             mobilePhones.Add(new MobilePhone("HTC", "OneX", true, false));
  28.  
  29.             comboBox1.DataSource = mobilePhones;
  30.             comboBox1.DisplayMember = "Brand";
  31.  
  32.             listBox1.DataSource = mobilePhones;
  33.             listBox1.DisplayMember = "Brand";
  34.             listBox1.SelectionMode = SelectionMode.MultiExtended;
  35.  
  36.  
  37.         }
  38.  
  39.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  40.         {
  41.             MobilePhone mobilePhone = (MobilePhone)comboBox1.SelectedItem;
  42.             label1.Text = mobilePhone.Model;
  43.         }
  44.  
  45.         private void button1_Click(object sender, EventArgs e)
  46.         {
  47.             string message = "";
  48.             bool isFirstPass = true;
  49.             //foreach (MobilePhone mobilePhone in listBox1.SelectedItems)
  50.             //{
  51.             //    if (isFirstPass)
  52.             //        message += mobilePhone.Model;
  53.             //    else
  54.             //        message += " , " + mobilePhone.Model;
  55.             //    isFirstPass = false;
  56.             //}
  57.             for (int i = 0; i < listBox1.SelectedItems.Count; i++)
  58.             {
  59.                 MobilePhone mobilePhone = (MobilePhone)listBox1.SelectedItems[i];
  60.                 if (i == 0)
  61.                     message += mobilePhone.Model;
  62.                 else
  63.                     message += " , " + mobilePhone.Model;
  64.             }
  65.             MessageBox.Show(message);
  66.         }
  67.     }
  68.     public class MobilePhone
  69.     {
  70.         public string Brand { get; set; }
  71.         public bool Camera { get; set; }
  72.         public bool TouchPad { get; set; }
  73.         public string Model { get; set; }
  74.         public MobilePhone(string brand, string model, bool camera, bool touchPad)
  75.         {
  76.             Brand = brand;
  77.             Camera = camera;
  78.             TouchPad = touchPad;
  79.             Model = model;
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement