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
|
private Dictionary<int, string> _origin;
Dictionary<int, bool> _results;
public Form1()
{
InitializeComponent();
_origin = new Dictionary<int, string>();
_origin.Add(1, "toto");
_origin.Add(2, "tata");
_origin.Add(3, "titi");
//by default, everything to false
_results = _origin.Select(o => o.Key).ToDictionary(o => o, o => false);
DataForDisplay[] displist = _origin.Select(o => new DataForDisplay() { key = o.Key, val = o.Value }).ToArray();
_checkedListBox.Items.AddRange(displist);
}
//classe juste pour l'affichage
private class DataForDisplay
{
public int key;
public string val;
public override string ToString()
{
return val;
}
}
//Met à jour les résultats dans la liste des résultats
private void button1_Click(object sender, EventArgs e)
{
foreach(int key in _checkedListBox.CheckedItems.OfType<DataForDisplay>().Select(o=>o.key))
{
_results[key] = true;
}
} |
Partager