VB.Net Combobox 显示引用值的文本 [英] VB.Net Combobox to display text which refers to a value

查看:26
本文介绍了VB.Net Combobox 显示引用值的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在组合框中显示多个项目,当用户选择时,将返回引用该文本的特定值而不是返回文本.对此的任何帮助将不胜感激.

I would like to display a number of items in a combobox and when the user selects on, instead of the text being returned a specific value referring to that text is returned. Any help with this would be much appreciated.

推荐答案

这是典型的 Key,Value 绑定.我将使用 Dictionary 作为示例.因此,假设您已经用正确的值填充了 Dictionary,代码可能如下所示:

This is a typical Key,Value binding. I will use a Dictionary, as an example. So assuming you have populated your Dictionary with proper values, the code can look like this:

ComboBox1.DataSource = yourDictionary.ToList
ComboBox1.DisplayMember = "Value"
ComboBox1.ValueMember = "Key"

然后您可以使用 ComboBox1.SelectedValue 属性选择值.

You can then pick the value using ComboBox1.SelectedValue property.

这篇关于VB.Net Combobox 显示引用值的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆