在C# WinForms应用程序中,要获取列表框项目的"密钥",可以使用以下方法:
using System.Collections.Generic;
using System.Windows.Forms;
Dictionary<string, string> listBoxItems = new Dictionary<string, string>();
listBoxItems.Add("key1", "项目1");
listBoxItems.Add("key2", "项目2");
listBoxItems.Add("key3", "项目3");
listBox1.DataSource = new BindingSource(listBoxItems, null);
listBox1.DisplayMember = "Value";
listBox1.ValueMember = "Key";
string key = listBox1.SelectedValue.ToString();
这样,当用户从列表框中选择一个项目时,您就可以获取到该项目的"密钥"。
领取专属 10元无门槛券
手把手带您无忧上云