2017-02-10 1 views
0

Ich habe ein paar verschiedene Wörterbuch-Strukturen, die ich in einer ComboBox anzeigen möchte.Anzeige Mitglieder des Wörterbuchs abhängig von Schlüssel in ComboBox

In JumpType.cs:

public SortedDictionary<int, List<string>> jumpCombination = new SortedDictionary<int, List<string>>(); 

Das Wörterbuch Struktur etwas wie folgt aussehen:

Key Values 
1  Flygande 
     EjFlygande 
2  Bak 
     Pik 
     Test 
3  ... 

ich zwei Comboboxen wie dies in meinem UI erstellt haben:

Select Key:  _____________ 
       | ComboBox | 
       --------------  __________ 
       _____________  | OK | 
Select Value: | ComboBox |  ---------- 
       -------------- 

In Form1.cs

InitializeComponent(); 
JumpType jt = new JumpType(); 
jt.addjumpCombination(); // populating the dictionary 
if (jt.jumpCombination != null) 
{ 
    comboBoxJumpComboKey.DataSource = new BindingSource(jt.jumpCombination, null); // Key => null 
    comboBoxJumpComboKey.DisplayMember = "Value"; 
    comboBoxJumpComboKey.ValueMember = "Key"; 
    comboBoxJumpComboValue.DisplayMember = "Value"; 
} 

Wie würde ich über gehen, um die entsprechenden Werte wählen entsprechend dem gewählten Schlüssel?

Vielen Dank im Voraus.

+0

Liste Werte = jumpCombination [key] – jdweng

Antwort

0

Sie Ihre Liste mit dem folgenden LINQ-Abfrage filtern:

var selectedValues = jumpCombination 
        .Where(j => j.Key == Convert.ToInt32(comboBoxJumpComboKey.SelectedItem.Value)) 
        .Select(a => a.Value) 
        .ToList(); 

Auch ist selectedValues ​​eine Sammlung von Liste, die Werte in Ihrem Fall ist

+0

Funktioniert leider nicht. SelectedItem.Value ist ungültige Syntax:/ – Joel

+0

Seltsam! Ist ComboBoxJumpComboKey ​​nicht ein Kombinationsfeld? Was ist mit ComboBoxJumpComboKey.SelectedValue? Funktioniert das für dich? – RRM

Verwandte Themen