Click to See Complete Forum and Search --> : Simple Combo Box Control Question...


Codejoy
April 24th, 2001, 04:32 PM
Hello, I have a combo box on my form which style has to be 2-Drop Down list. There is an instance though where i load data onto the form from a database, and I want to set the combo box whose style is 2 to a integer i grab from the database. It keeps saying since its style is two that its a read only. I cannot change the style since what I load from the DB is a control ID that the user cannot change, but I read and save out that Id from the combo box on the save/edit. Any way to set this combo box to the number I need by searching its array some how? Code would help. Thanks

Regards,
Shane

forty7
April 24th, 2001, 07:00 PM
Could you include some code?
I tried this:

option Explicit

private Sub Command1_Click()
me.Combo1.Text = "3"
End Sub

private Sub Form_Load()
me.Combo1.AddItem "1"
me.Combo1.AddItem "2"
me.Combo1.AddItem "3"
me.Combo1.AddItem "4"
End Sub



It worked fine for me.
This was in a new project where combo1 is style 2. Is this what you were trying to do?

thanx/good luck,
adam

shree
April 24th, 2001, 08:58 PM
For a combo box with the Drop Down list style, you cannot set the text using the combo1.text = "Something". You do it using the ListIndex property. You should know the ListIndex of the item you want to display (or you can search using a for loop) then set Combo1.ListIndex to that value.

Codejoy
April 24th, 2001, 11:11 PM
Hmm okay I get the listindex, i wasn't sure how to search the combo box. What were those methods?

Thanks

-Shane

d.paulson
April 25th, 2001, 05:34 AM
Just FYI. You can set Combo1.text = "Something" as long as "Something" is in the list. This means that the item must be added to the list first. To do
combo1.additem "Something"
combo1.text = "Something" is perfectly okay.

David Paulson