I added 3 items to the comboBox in the form, using the Items property. These items are: Item1, Item2, Item3.
When I select any of these 3 items in the comboBox, I want it to show a messagebox that contains the value of the first attribute of the corresponding object. For example when i click Item1, I want it to show me attribute "CNP1" from object a1, when I click Item2, to show me attribute CNP2 from object a2 and so on.
I think that I might connect each item in the comboBox with one of the 3 object created, not just write down these names(Item1,Item2,Item3) but I don't know how.
Also, these 3 items are created due to a class I created in the same project. I only have a class, a form and the main Program in this project.
So, how can I connect a comboBox Item to one of these objects, especially with only one attribute of that object. Thank you.
using System;
using System.Collections;
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 IncercareEX2015
{
public partial class PreluareDate : Form
{
ArrayList listaAbonati;
AbonatTelefonic ab;
public PreluareDate()
{
InitializeComponent();
double[] vectMin = new double[4] { 12, 15, 50, 20 };
AbonatTelefonic a1 = new AbonatTelefonic("CNP1", "Nume1", "Adresa1", "tel1", "tip1", vectMin);
double[] vectMin3 = new double[2] { 100, 130 };
AbonatTelefonic a3 = new AbonatTelefonic("CNP3", "Nume3", "Adresa3", "Tel3", "Tip3", vectMin3);
double[] vectMin2 = new double[3] { 200, 80, 150 };
AbonatTelefonic a2 = new AbonatTelefonic("CNP2", "Nume2", "Adresa2", "Tel2", "Tip2", vectMin2);
///GENERARE COLECTIE DE OBIECTE
ArrayList listaAbonati = new ArrayList();
listaAbonati.Add(a1);
listaAbonati.Add(a3);
listaAbonati.Add(a2);
listaAbonati.Sort();
}
private void comboBox1_nume_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (object o in listaAbonati)
MessageBox.Show(o.ToString());
}
}
}