2017-02-10 12 views
0

コンボボックスに表示するいくつかの異なる辞書構造があります。コンボボックス内のキーに応じて辞書のメンバーを表示

JumpType.csで:

Select Key:  _____________ 
       | ComboBox | 
       --------------  __________ 
       _____________  | OK | 
Select Value: | ComboBox |  ---------- 
       -------------- 
:私はこのように私のUIに2つのコンボボックスを作成しました

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

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

辞書の構造は以下のようになります

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"; 
} 

選択したキーに応じて、対応する値を選択する方法を教えてください。

ありがとうございます。

+0

一覧値= jumpCombination [キー] – jdweng

答えて

0

あなたは、次のLINQクエリを使用してリストをフィルタリングすることができます

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

また、selectedValuesは、あなたのケースで

+0

あるリストのコレクションです残念ながら働かない。 SelectedItem.Valueは無効な構文です:/ – Joel

+0

奇妙な! comboBoxJumpComboKey​​はコンボボックスではありませんか? comboBoxJumpComboKey​​.SelectedValueはどうでしょうか?それはあなたのために働くのですか? – RRM

関連する問題