Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning ComboBox Item from list 1

Status
Not open for further replies.

Bloobird

Programmer
Oct 23, 2001
49
0
0
GB
Forgive my stupididty, but I'm quite new to VB. I have a drop down listbox which I initalise with list of string values ("Jon", "Gary" etc) - I then return a value from a database, and want to display the corresponding text value returned in the combo box - for example, if "Jon" is returned from the database, I want "Jon" to be displayed as the value in the drop downlist - I assumed I could set the .Text property, however it says this is read only at runtime ... how can I do this ? Thanks
 
Try This

valueFromTable = "John"
combo1.AddItem valueFromTable
 
This seems to Add the Item to the list, for example if "John" was already in the list, it will be added again, giving me 2 "John"s in the list, but without actually setting "John" to be the displayed value. What I need is a method to set "John", which is already in the list, to be displayed as the default value, and not to add the value to the list again.

Thanks
 
Dim Name As String, i As Integer

Name = "John"

For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) = Name Then
Combo1.ListIndex = i
Combo1.SelStart = 0
Combo1.SelLength = Len(Combo1)
Exit Sub
End If
Next i
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top