【问题标题】:Value of combobox in vb?vb中组合框的值?
【发布时间】:2013-12-04 01:46:04
【问题描述】:
所以我正在做一个项目,我需要在一个炸弹框中设置每个项目。例子:
组合框下方的“Google”和“Facebook”中的组合框有一个网络浏览器,当我按下按钮时,浏览器导航到所需的链接,我已经完成了这部分,出现的问题是我不知道如何设置每个项目的链接,为 Google 选项设置 www.google.com,甚至在 facebook 中设置 .. 有人可以帮助我吗?
【问题讨论】:
标签:
visual-studio
visual-studio-2012
【解决方案1】:
组合框有 2 个可用于此目的的属性。 DisplayMember 是您在 GUI 中看到的内容,而 ValueMember 是您可以用来根据用户选择导航到的内容。示例:
Dim myDt As New DataTable() 'define a datatable to hold the combo box data
Dim dt As New DataTable()
dt.Columns.Add("Site")
dt.Columns.Add("URL")
'*** Load the combobox with data
dt.Rows.Add("Google", "www.google.com")
dt.Rows.Add("Facebook", "www.facebook.com")
'***add other rows you might have here
'*** now bind the datatable to the combobox
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "Site" 'for example Google
ComboBox1.ValueMember = "URL" 'for example www.Google.com
在您选择的事件中,用户从组合框中选择一个条目后,您可以发出:
'***Launch the site that corresponds to the selected item in the combobox
System.Diagnostics.Process.Start(ComboBox1.SelectedValue)
您可以使用其他方式启动到所选站点的导航,例如:Open Web Page from App。