本文介绍了VB6根据数据库数据选择组合框文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到基于从数据库中检索到的值来为ComboBox对象设置值的方法.当我填充comboBox时,我使用以下代码:
I can't find a way to set a value to the ComboBox object based on the value retrieved from a DB.When I fill the comboBox, I use this code:
Do while Not rs1.EOF
Cboneighborhood.AddItem rs1!Description
Cboneighborhood.ItemData(CboBarrio.NewIndex) = rs1!Idneighborhood
Loop
当我检索员工的数据时(Employee表中有一个名为IdNeighborhood的字段),我希望组合框设置与该ID匹配的文本值.
When I retrieve data for an employee (Employee table has a field called IdNeighborhood) I want the combobox to set the text value that matches this ID.
我无法使用该物业
Cboneighborhood.Text
因为这是2-DropDown列表类型.
'cause it's a 2-DropDown List type.
您的帮助将不胜感激.预先感谢
Your help would be really appreciated.Thanks in advance
推荐答案
当您获得Value
时,您只需要遍历这样的项目即可:
You just need to iterate through the items like this when you get a Value
:
'Reset to no item.
Cboneighborhood.ListIndex = -1
Dim X As Integer
'Iterate through items.
For X = 0 To Cboneighborhood.ListCount - 1
'Compare value.
If Cboneighborhood.ItemData(X) = Value Then
'Select it and leave loop.
Cboneighborhood.ListIndex = X
Exit For
End If
Next X
这篇关于VB6根据数据库数据选择组合框文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!