gpt4 book ai didi

mysql - VB.Net "mask"组合框文本作为另一个文本

转载 作者:行者123 更新时间:2023-11-29 08:18:12 25 4
gpt4 key购买 nike

所以我有一个组合框,其中包含来自 MySql 数据库的表名称,它们会在表单加载时使用 show table 查询自动列出。

是否有办法在组合框中显示其他内容,但文本值仍然是原始表名称?

最佳答案

这并非不可能。这是一个简单的例子:

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

' This would be whatever you are pulling from the database. For the purpose of this example, it is just mock data.
Dim dataFromDatabase As IEnumerable(Of String) = {"1st table from db", "2nd table from db", "etc."}

' What you actually want to display in the combobox. It should be in the same order as above and have the same number of items. Items must be unique.
Dim valuesToDisplayInComboBox As IEnumerable(Of String) = {"1st item", "2nd item", "3rd item"}


' This is what ties the two together. You would probably want this to be larger in scope than this example.
Dim dataCollection As New Dictionary(Of String, String)
For i As Integer = 0 To dataFromDatabase.Count - 1 Step 1
dataCollection.Add(valuesToDisplayInComboBox(i), dataFromDatabase(i))
Next

ComboBox1.DataSource = valuesToDisplayInComboBox

End Sub
End Class

现在您有一个将两者链接在一起的Dictionary,因此每当用户在组合框中选择某些内容时,您都会转到Dictionary并查找相应的表名称。

关于mysql - VB.Net "mask"组合框文本作为另一个文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20146919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com