2011-10-30 22 views
0

私は自分のアプリケーションでお気に入りを作ろうとしており、ListBoxにお気に入りの名前を持つフォームを表示する必要があります。 名前を選択して選択ボタンをクリックすると、名前とURLを別のテキストボックスに入れたいと思います。これは私のコードです。ListBoxを辞書から挿入して、値とキーを別々に取得する必要があります

 private void EditFourites_Click(object sender, EventArgs e) 
    { 
     textBox1.Text = listBox1.SelectedItem.ToString();//put the selected value from the listbox to the textbox1 and this is my problem i want to make textbox1.text takes only the key of the listbox1.text 


    } 

    private void ListBox() 
    { 
     FavoriteXml FV = new FavoriteXml();//the favouritXml class is a class where i get the information about favourites 
     Dictionary<string, string> Favourite = FV.GetFavouriteCombo();//GetFavouriteCombo() will get the value as dictionary 

     listBox1.DataSource = new BindingSource(Favourite, null); 

     listBox1.ValueMember = "Value"; 
    } 

    private void EditSpecificFavourite_Click(object sender, EventArgs e) 
    { 
     FavoriteXml FV = new FavoriteXml(); 
     FV.EditFavourite(textBox1.Text.ToString(),textBox2.Text.ToString());//this is the EditFavourite where i want to change the specific favourite 
     ListBox(); 
    } 

答えて

0

あなたはこのコードを使用する2番目のテキストボックスに、選択しlistboxitemのDataValueはを取得するには:オーケー

textBox2.Text = listBox1.SelectedValue.ToString(); 
+0

この仕事をしてくれ選択された値を取得しますが、私は別のテキストボックスに、あまりにもキーを入れたいです –

+0

キーとはどういう意味ですか?リストボックス項目は2つの値しか表示できません。表示できる値と "SelectedValue"です。 – fgblomqvist

+0

私はリストボックスのソースをバインドするとき、私は辞書から2つの値を挿入していますキーとあなたの答えの値私は値を取得するだけでも、辞書のキーも欲しい –

関連する問題