1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinCombox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[,] arData = new string[,]
{
{"1" , "Chaise"} ,
{ "2" , "Table"},
{ "3" , "Escalier"},
{ "4" , "Bibliotheque" },
{ "5" , "Tabouret"} ,
{ "6" , "Bar"} ,
{ "7", "Buffet"},
{ "8" , "Lit"} ,
{ "9" , "Table de nuit"},
{ "10" , "Meuble" }
};
List<DataItem> Liste = new List<DataItem>();
DataItem myDataItem;
for (int i = 0; i < arData.GetLength(0); i++)
{
myDataItem = new DataItem();
myDataItem.TextNom = arData[i, 1];
myDataItem.Value = arData[i, 0];
/* add to your list */
Liste.Add(myDataItem);
}
/* la liste est pleine */
/* on la binde à combo en precisant DisplayMember & ValueMember.... */
comboBox1.BeginUpdate();
comboBox1.DataSource = Liste;
comboBox1.DisplayMember = "TextNom";
comboBox1.ValueMember = "Value";
comboBox1.EndUpdate();
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex ==-1) return;
this.textBox1.Text="vous avez selectione : " + ((DataItem)comboBox1.SelectedItem).TextNom+ Environment.NewLine;
this.textBox1.Text = this.textBox1.Text + "numero :" + comboBox1.SelectedValue;
}
}
public class DataItem
{
public string TextNom { get; set; }
public string Value { get; set; }
}
} |
Partager