Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在组合框中显示许多项目,并且当用户选择打开时,而不是返回文本,而是返回引用该文本的特定值。对此的任何帮助将不胜感激。
这是典型的Key,Value绑定。我将使用Dictionary, 作为示例。因此,假设您已经使用正确的值填充了 Dictionary,代码可能如下所示:
Key,Value
Dictionary
ComboBox1.DataSource = yourDictionary.ToList ComboBox1.DisplayMember = "Value" ComboBox1.ValueMember = "Key"
然后,您可以使用ComboBox1.SelectedValue属性选择值。
ComboBox1.SelectedValue