VB6 Select combobox text value based on database data

馋奶兔 提交于 2019-12-11 02:43:39

问题


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

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.

I can't use the property

Cboneighborhood.Text 

'cause it's a 2-DropDown List type.

Your help would be really appreciated. Thanks in advance


回答1:


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


来源:https://stackoverflow.com/questions/18422210/vb6-select-combobox-text-value-based-on-database-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!