-
hi
i have a combo box with 5 options in it
sound 1
sound 2
sound 3
sound 4
sound 5
and i have set the style to 2, but when the program runs the option box is blank, i can't change the text because it is read only with this style option so i was wondering how i could set a default option to be in the combo box when the program runs.
thanks
-
In design mode, set the text property to which ever option you want as the default.
-
I tried that, but i have set the style to 2 and that means that i can't change it, it says that this is set to read only, if i change the style to 1 then change the text and then change the style back to 2 it still comes up wrong, any more ideas ??
-
isn't there a Selected property? try
Code:
Combo1.Selected(0) = True
-
No there isn't a selected option, and even if i type it in it still doesn't work, it says method or data member not found, any more ideas
sorry to be a nuisance :rolleyes:
-
scratch that, use this :
Code:
Private Sub Form_Load()
Combo1.Text = Combo1.List(0) ' where 0 is the index of your default
End Sub
-
Guess what,
Code:
'text' property is read only
aaagggghhhhh
is there a way to do this at all?? i would of thought that your last suggestion would of worked:(
-
Actually, its better to set the ListIndex property because it will actually set an item rather than just change the text.
Code:
'Set the 1st item to the default.
Combo1.ListIndex = 0
-
its worked for me, and I have the style set to '2' and every thing...
-
it still doesn't work,
what could i have done to stop this working,
here is my code
Code:
Combo1.AddItem "sound 1"
Combo1.AddItem "sound 2"
Combo1.AddItem "sound 3"
Combo1.AddItem "sound 4"
Combo1.AddItem "sound 5"
'Code improved by vBulletin Tool (Save as...)
andi have the style set to 2, what am i doing wrong ??
-
it ok one of my friends helped me with the problem, i had the code like this
Code:
Private Sub Form_Load()
Combo1.Text = Combo1.List(0)
Combo1.AddItem "sound 1"
Combo1.AddItem "sound 2"
Combo1.AddItem "sound 3"
Combo1.AddItem "sound 4"
Combo1.AddItem "sound 5"
End Sub
'Code improved by vBulletin Tool (Save as...)
instead of like this
Code:
Private Sub Form_Load()
Combo1.AddItem "sound 1"
Combo1.AddItem "sound 2"
Combo1.AddItem "sound 3"
Combo1.AddItem "sound 4"
Combo1.AddItem "sound 5"
Combo1.Text = Combo1.List(0)
End Sub
'Code improved by vBulletin Tool (Save as...)
thanks for all of your help and sorry for being a nuisance :rolleyes:
-
sorry to be a nuisance (again :rolleyes:) but once i have set the default combo item, i would like a way for the program to remeber what the last selection was so that next time the program is run it will have the last one selected as the option
e.g program runs for the 1st time and "sound 1" is default, the user decides that they like "sound 2" they select this one and close the program, when the program runs next instead of "sound 1 being default" "sound 2" should be.
sorry if this doesn't make sense, thanks for all of your help
-
makes sense enough, you can use a file or the registry to store the selected item when the app ends, then open the file/registry key and set it that way instead of hard-coding the 0 in there.
-
again sorry for being a pain, but do you have any code examples ??
-
i have never used the registry before, but here's a file example...
Code:
Private Sub Form_UnLoad()
Open app.Path & "\data.dat" For Output As #1
Print #1, Combo1.ListIndex
Close #1
End Sub
Private Sub Form_Load()
Dim Index As Integer
If Dir$(app.Path & "\data.dat") <> "" Then
Open app.Path & "\data.dat" For Input As #1
Input #1, Index
Close #1
Combo1.ListIndex = Index
End If
End Sub
-
That is brilliant, thank you very much crptcblade for all of your help and time :)
-