Bonjour à tous,

Je voudrais lié une valeur à un item de mon combobox par exemple

Value Text
5 Maison
10 Jardin
3 Auto

Je pense avoir trouvé voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 public class ComboBoxItem
        {
            public string Value;
            public string Text;
            public ComboBoxItem(string val, string text)
            {
                Value = val;
                Text = text;
            }
 
            public override string ToString()
            {
                return Text;
            }
        }
 
// collone 1
            var md1 = (from m in db.Conditions
                       where m.Collone == 1
                       select new { m.Condition1, m.Id });
 
            foreach (var m in md1)
            {
                comboBoxCondition11.Items.Add(new ComboBoxItem(m.Id.ToString(), m.Condition1));
                comboBoxCondition11.ValueMember = m.Id.ToString();
            }
Je suis arrivé ou je dois récupérer la valeur de mon item sélectionnée dans mon combobox.

J'ai essayé ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 string test;
            test = comboBoxCondition12.SelectedValue.ToString();
            MessageBox.Show(test);
mais il me met :

Object reference not set to an instance of an object.
Pouvez-vous me dire pourquoi cela ne fonctionne pas ?

Merci d'avance