2012-05-13 5 views
1

まず、Javaで作成したアプリケーションを再作成しようとすると、C#で非常に新しいです。4つのリストボックスをリンクする

私は4つのリストボックスを持っています。各ボックスにはxmlファイルの値のリストが保持されます。

listBox_year for <Year><Make>の場合は listBox_makeです。 <Model>の listBox_model。 listBox_subModelは<sub-Model>です。

したがって、年を重複せずにすべての年をlistBox_yearに追加することができます。一年をクリックすると、その年のすべてのMakeの自動車メイクが表示されます。次に、Makeをクリックすると、その年の下にMake Ssのモデルが表示されます。

Java withこの仕事をするためにHashMapを使用することができました。同じ名前と私は今年のキーがこれまでのキーを検索することができます。その年をキーとするすべてのメイクまたはバリューを取得します。ここで

は、XML形式は、Javaのハッシュマップに最も近いタイプ辞書である

<?xml version="1.0" encoding="utf-8" ?> 
<vehicles> 

    <Manufacturer> 
    <Make>Subaru</Make> 
    <Year>2010</Year> 
    <Model>Impreza</Model> 
    <Sub-Model>2.0i</Sub-Model> 
    <Highway>36 MPG highway</Highway> 
    <City>27 MPG city</City> 
    <Price>$17,495</Price> 
    <Description> 
     Symmetrical All-Wheel Drive. 
     SUBARU BOXER® engine. 
     Seven airbags standard. 
     >Vehicle Dynamics Control (VDC). 
    </Description> 
    </Manufacturer> 

    <Manufacturer> 
    <Make>Toyota</Make> 
    <Year>2012</Year> 
    <Model>Supra</Model> 
    <Sub-Model>TT</Sub-Model> 
    <Highway>22 MPG highway</Highway> 
    <City>19 MPG city</City> 
    <Price>$48,795</Price> 
    <Description> 
     16-inch aluminum-alloy wheels. 
     6-speaker audio system w/iPod® control. 
     Bluetooth® hands-free phone and audio. 
     Available power moonroof. 
    </Description> 
    </Manufacturer> 

    <Manufacturer> 
    <Make>Subaru</Make> 
    <Year>2011</Year> 
    <Model>Impreza</Model> 
    <Sub-Model>2.0i Limited</Sub-Model> 
    <Highway>36 MPG highway</Highway> 
    <City>27 MPG city</City> 
    <Price>$18,795</Price> 
    <Description> 
     16-inch aluminum-alloy wheels. 
     6-speaker audio system w/iPod® control. 
     Bluetooth® hands-free phone and audio. 
     Available power moonroof. 
    </Description> 
    </Manufacturer> 

    <Manufacturer> 
    <Make>Subaru</Make> 
    <Year>2011</Year> 
    <Model>Impreza</Model> 
    <Sub-Model>2.0i Limited</Sub-Model> 
    <Highway>36 MPG highway</Highway> 
    <City>27 MPG city</City> 
    <Price>$18,795</Price> 
    <Description> 
     16-inch aluminum-alloy wheels. 
     6-speaker audio system w/iPod® control. 
     Bluetooth® hands-free phone and audio. 
     Available power moonroof. 
    </Description> 
    </Manufacturer> 

</vehicles> 
+1

ご質問はありますか?あなたは 'Dictionary'を探していますか? – SLaks

+0

コレクションが呼び出されたのはわかりませんが、@ lcfsethのように思えるように思われます。 –

答えて

1

です。同じキーを持つ複数のアイテムが必要なので、Dictionary<int,List<Item>>を使用します。 必要な基本機能は次のとおりです。

void AddItem(int key, Item i, Dictionary<int,List<Item>> dict) 
{ 
    if (!dict.ContainsKey(key)) 
    { 
     dict.Add(i,new List<Item>()); 
    } 
    dict[key].Add(i); 
} 

List<Item> GetList(int key) 
{ 
    if (dict.ContainsKey(key)) 
    { 
     return dict[key]; 
    } 
    else 
    { 
     return new List<Item>(); // can also be null 
    } 
} 
+0

ありがとう、私はこれを試してみます。私はしばらくサイトにいませんでした。 –

関連する問題