View Full Version : trying to use combobox
sandyrepope
03-07-2007, 04:18
I'm trying to use a combobox and am having trouble. I get a combobox by using control add combobox but when I try to use combobox add to add text to the box none of my strings gets in the box.
control add COMBOBOX, hDlg, ,%ID_COMBO, "", 5, 75, 40, 75, %CBS_DROPDOWN
combobox add hDlg, %ID_COMBO, "January"
combobox add hDlg, %ID_COMBO, "February"
combobox add hDlg, %ID_COMBO, "March"
combobox add hDlg, %ID_COMBO, "April"
combobox add hDlg, %ID_COMBO, "May"
combobox add hDlg, %ID_COMBO, "June"
combobox add hDlg, %ID_COMBO, "July"
combobox add hDlg, %ID_COMBO, "August"
combobox add hDlg, %ID_COMBO, "September"
combobox add hDlg, %ID_COMBO, "October"
combobox add hDlg, %ID_COMBO, "November"
combobox add hDlg, %ID_COMBO, "December"
COMBOBOX SELECT Hdlg, %ID_COMBO, 1
Am I doing something wrong?
Thanks
Sandy
ErosOlmi
03-07-2007, 05:37
Sandy,
please use:
control add COMBOBOX, hDlg, %ID_COMBO, , 5, 75, 40, 75, %CBS_DROPDOWN
There is an erro in documentation. After %ID_COMBO a string array is expected but if nothing has to be passed, just leave empty.
Correct syntax is something like:
CONTROL ADD COMBOBOX , hDlg, id&, [items$()], x, y, xx, yy [, [style&] [, [exstyle&]]]
Sorry.
Eros
sandyrepope
03-07-2007, 17:27
I've tried using a string array with combobox but it doesn't work. It says the array subscript is out of range. It says the array needs to be between 1 and 12 but that the present value is 0.
I'm attaching a copy of the error box I'm getting.
I thought that arrays started at 1 and not 0.
Thanks
ErosOlmi
04-07-2007, 14:36
Hi Sandy,
sorry for the delay but yesterday was a strange day for me.
I've checked again and should work fine. I will improve possibility to pass both array or string expressions when creating LISTBOX or COMBOBOX but this is future.
Can you please see if you can execute the following code?
It creates two COMBOBOX filling them in two different ways: by an array and by an ADD loop.
uses "UI"
DIM Msg AS LONG
DIM wParam AS LONG
DIM lParam AS LONG
DIM hDlg AS LONG
DIM Count AS LONG
'---Create a new dialog
DIALOG NEW 0, "ListBox example", -1, -1, 400, 300, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, _
0 TO hDlg
%Label01 = 400
%Combo01 = 401
%Label02 = 405
%Combo02 = 406
%ButtClose = 410
randomize
dim MaxElements as long = 100
DIM vList(MaxElements) AS STRING
FOR count = 1 TO MaxElements
vList(Count) = "Item ViaArray " & FORMAT$(RND(1, 100000), "000000")
NEXT
'---Show dialog in MODELESS state, the only managed state at the moment
DIALOG SHOW MODELESS hDlg
'---Start the main message loop
WHILE IsWindow(hDlg)
'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)
'---Now test the message
SELECT CASE Msg
case %WM_INITDIALOG '---Message fired at the very beginning when dialog is initialized
'---This can be the right place to initialize dialog or create controls
CONTROL ADD label , hDlg, %Label01 , "ComboBox filled with an array" , 5, 5, 200, 12
'---Filled with Array
CONTROL ADD combobox , hDlg, %Combo01 , vList() , 5, 20, 200, 12
CONTROL ADD label , hDlg, %Label02 , "ComboBox filled by an ADD operation" , 5, 55, 200, 12
'---Filled with COMBOBOX ADD
CONTROL ADD combobox , hDlg, %Combo02 , , 5, 70, 200, 12
FOR count = 1 TO MaxElements
COMBOBOX ADD hDlg, %Combo02, "Item ViaADD " & FORMAT$(RND(1, 100000), "000000")
NEXT
CASE %WM_SYSCOMMAND
SELECT CASE wParam
CASE %SC_CLOSE
EXIT WHILE
END SELECT
END SELECT
WEND
DIALOG END hDlg
If it doesn't work, can you please:
- check which thinBasic version you have installed of thinBasic\Lib\thinBasic_UI.DLL file
- send me your source via personal message or post here if not reserved info
Thanks
Eros
sandyrepope
04-07-2007, 15:58
ErosOlmi
I downloaded your example and ran it. It ran just fine. Looks like I've got something wrong with my script. I'll compare your example with what I am trying to do and I think I'll find out my mistake.
Thanks
Sandy
sandyrepope
05-07-2007, 18:27
I have one last question about combobox.
Does it always put the strings in alphabetical order?
Is there some way to have it display the strings in the same order as they are in the array?
Thanks
Sandy
ErosOlmi
05-07-2007, 18:42
Yes, sure. Just specify a Style other than leaving empty.
Example
CONTROL ADD combobox , hDlg, %Combo02 , , 5, 70, 200, 12
will create a SORTed combo
while
CONTROL ADD combobox , hDlg, %Combo02 , , 5, 70, 200, 12, %CBS_DROPDOWN OR %CBS_HASSTRINGS OR %WS_TABSTOP
will not create a sorted combo
If style is left empty, some defaulted value will be entered. In this case default values for style are:
%CBS_DROPDOWN OR %CBS_HASSTRINGS OR %CBS_SORT OR %WS_TABSTOP
Again I should add more info into help material ... :-[
Ciao
Eros