C# 从字典中插入列表框,我需要将值和键分开

C# 从字典中插入列表框,我需要将值和键分开,c#,winforms,dictionary,listbox,key,C#,Winforms,Dictionary,Listbox,Key,我正在尝试在我的应用程序中创建收藏夹,我需要在列表框中显示一个包含收藏夹名称的表单。 当选择一个名字并点击选择按钮时,我想把名字和Url放在不同的文本框中,这是我的代码 private void EditFourites_Click(object sender, EventArgs e) { textBox1.Text = listBox1.SelectedItem.ToString();//put the selected value from the l

我正在尝试在我的应用程序中创建收藏夹,我需要在列表框中显示一个包含收藏夹名称的表单。 当选择一个名字并点击选择按钮时,我想把名字和Url放在不同的文本框中,这是我的代码

       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();
    }
private void EditFourites\u单击(对象发送方,事件参数e)
{
textBox1.Text=listBox1.SelectedItem.ToString();//将所选值从列表框放入textBox1,这是我的问题,我想让textBox1.Text只使用listBox1.Text的键
}
私有无效列表框()
{
FavoriteXml FV=new FavoriteXml();//FavoriteXml类是一个获取有关Favorites的信息的类
Dictionary Favorite=FV.GetFavoriteCombo();//GetFavoriteCombo()将作为Dictionary获取值
listBox1.DataSource=新的BindingSource(收藏夹,空);
listBox1.ValueMember=“Value”;
}
私有void编辑器单击(对象发送者,事件参数e)
{
FavoriteXml FV=新的FavoriteXml();
FV.editFavorite(textBox1.Text.ToString(),textBox2.Text.ToString());//这是我要更改特定收藏夹的editFavorite
ListBox();
}

要将所选listboxitem的数据值放入第二个文本框,请使用以下代码:

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

好的,这项工作,让我选择的值,但我想把键也放在另一个文本框你说的键是什么意思?listboxitem只能包含两个值,一个是您可以看到的值,另一个是“SelectedValue”。我的意思是,当我为listboxitem绑定源代码时,我从字典中插入了两个值,即键和答案中的值,我只得到我想要的字典键的值