在vb2010中的组合框和文本框 [英] Combobox and text box in vb2010
问题描述
亲爱的朋友
我使用1-comboBox,1-TextBox,2-Button
我的代码
Public Class Form1
$
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
Dim comboSource As New Dictionary(Of Integer,String)()
comboSource.Add(25," Anbu")
comboSource.Add(20,"Rose")
comboSource.Add(45," Siva")
comboSource.Add(75," Srini")
comboSource.Add(60,"Nazar")
comboSource.Add(40," Sakthi")
comboSource.Add(65," Vince")
ComboBox1.DataSource = New BindingSource(comboSource,Nothing)
ComboBox1.DisplayMember =" Value"
ComboBox1.ValueMember =" Key"
结束点¥
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click
Dim key As String = DirectCast(ComboBox1.SelectedItem,KeyValuePair(Of Integer,String))。键
昏暗值As String = DirectCast(ComboBox1.SelectedItem,KeyValuePair(Of Integer,String))。值
MessageBox.Show(key&" "& value)
结束点¥
Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button2.Click
结束时分
结束等级
我的要求
如果我点击button1然后留言 show combobox 显示成员和值成员。
我想,我将在Textbox中给出值成员,comboBox将显示相关的显示成员。 我做了什么?
帮助我。
谢谢
Anburose
这是一个可能满足您需求的示例
cboDepartments.AutoCompleteMode = AutoCompleteMode.SuggestAppend
cboDepartments.AutoCompleteSource = AutoCompleteSource.ListItems
cboDepartments.DropDownStyle = ComboBoxStyle.DropDown
Dim ops = New Operations
Dim bs As New BindingSource
bs.DataSource = ops.Deparments
cboDepartments.DataSource = bs
cboDepartments.DisplayMember =" key"
cboDepartments.ValueMember =" value"
TextBox1.DataBindings.Add(" Text",bs," Key")
TextBox2.DataBindings.Add(" Text",bs," Value")
除TextBox控件外
完整示例在这里从数据库表中获取数据,但无法使用数据库表也。可能有一些代码需要调整,因为我在Visual Studio 2017中这样做,多年没有使用VS2010。
Dear Friend
i use 1-comboBox, 1-TextBox , 2-Button
my code
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim comboSource As New Dictionary(Of Integer, String)()
comboSource.Add(25, "Anbu")
comboSource.Add(20, "Rose")
comboSource.Add(45, "Siva")
comboSource.Add(75, "Srini")
comboSource.Add(60, "Nazar")
comboSource.Add(40, "Sakthi")
comboSource.Add(65, "Vince")
ComboBox1.DataSource = New BindingSource(comboSource, Nothing)
ComboBox1.DisplayMember = "Value"
ComboBox1.ValueMember = "Key"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim key As String = DirectCast(ComboBox1.SelectedItem, KeyValuePair(Of Integer, String)).Key
Dim value As String = DirectCast(ComboBox1.SelectedItem, KeyValuePair(Of Integer, String)).Value
MessageBox.Show(key & " " & value)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
End Class
My Request
if i click button1 then message show combobox display member and value member.
i want , i will give the value member in Textbox, comboBox will display the related display member. what i do?
help me pls.
Thanks
Anburose
Here is an example that may suit your needs
cboDepartments.AutoCompleteMode = AutoCompleteMode.SuggestAppend cboDepartments.AutoCompleteSource = AutoCompleteSource.ListItems cboDepartments.DropDownStyle = ComboBoxStyle.DropDown Dim ops = New Operations Dim bs As New BindingSource bs.DataSource = ops.Deparments cboDepartments.DataSource = bs cboDepartments.DisplayMember = "key" cboDepartments.ValueMember = "value" TextBox1.DataBindings.Add("Text", bs, "Key") TextBox2.DataBindings.Add("Text", bs, "Value")Except for the TextBox controls the full example is here which gets data from a database table but will work w/o a database table also. There may be some code that needs tweaking as I did this in Visual Studio 2017, have not had VS2010 for many years.
这篇关于在vb2010中的组合框和文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!