PDA

View Full Version : Sample of DELETE with COMBOBOX



marcuslee
09-09-2008, 16:45
Here's a sample ... oh, you can read the title of this topic.

Anyway, I like the comment under the topic MENU DELETE about the Position.



Position is the position of the menu item, where Position = 1 for the first position, Position = 2 for the second, and so on.


I think a similar phrase should appear with the COMBOBOX and LISTBOX versions.

Now, here's my sample, which was adapted from a script posted in this topic (http://community.thinbasic.com/index.php?topic=1019.0):




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
%ID_BUTTON = 402
%Label02 = 403

RANDOMIZE

DIM MaxElements AS LONG = 10
DIM vList( MaxElements ) AS STRING

FOR count = 1 TO MaxElements
vList( Count ) = "Item ViaArray " & count
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
CONTROL ADD LABEL, hDlg, %Label02, "Click the button to delete the item of your choice from the combobox", 300, 50, 100, 30
CONTROL ADD COMBOBOX, hDlg, %Combo01, vList( ), 5, 20, 200, 12, %CBS_DROPDOWN OR %CBS_HASSTRINGS OR %WS_TABSTOP
CONTROL ADD BUTTON, hDlg, %ID_BUTTON, "Delete an Item", 300, 10, 80, 25
CASE %WM_COMMAND
SELECT CASE wParam
CASE %ID_BUTTON
ITEMDELETE
END SELECT
CASE %WM_SYSCOMMAND
SELECT CASE wParam
CASE %SC_CLOSE
EXIT WHILE
END SELECT
END SELECT
WEND

DIALOG END hDlg

FUNCTION ITEMDELETE( )
DIM s AS LONG
s = INPUTBOX$( "Which item would you like to delete?", "Delete an Item", "Type a number from 1 to " & MaxElements )
MSGBOX 0, "deleting item number " & s & "."
'This DELETE command will take out the item specified with the InputBox.
COMBOBOX DELETE hDlg, %Combo01, s
END FUNCTION




Mark ;D