PUBLIC goForm
goForm = CREATEOBJECT("MyForm")
goForm.Show()
READ EVENTS
CLOSE ALL
CLEAR ALL
**********
DEFINE CLASS MyForm as Form
cCountry = ""
DIMENSION aSelection[1]
Width = 480
Height = 270
MinWidth = This.Width
MinHeight = This.Height
MaxWidth = This.Width
Caption = "Cars on Stock - Multiselect CTRL + click"
AutoCenter = .T.
ShowTips = .T.
Themes = .F.
ADD OBJECT lblReturnValue as Label WITH ;
Top = 132, ;
Left = ThisForm.Width - 126, ;
Caption = "Listbox return value", ;
AutoSize = .T., ;
Anchor = 9
ADD OBJECT opgChoice as OptionGroup WITH ;
Top = 12, ;
Left = ThisForm.Width - 126, ;
ButtonCount = 6, ;
Value = 6, ;
AutoSize = .T., ;
Anchor = 9
PROCEDURE opgChoice.Init()
LOCAL loButton
FOR i = 1 TO This.ButtonCount
WITH This.Buttons(i)
.AutoSize = .T.
.Caption = ICASE(i = 1, "US cars", i = 2, "FR cars", i = 3,"DE cars", i = 4, "GB cars", i = 5, "IT cars", "All")
ENDWITH
ENDFOR
ENDPROC
PROCEDURE opgChoice.Click()
DO CASE
CASE This.Value = 1
ThisForm.cCountry = "US"
CASE This.Value = 2
ThisForm.cCountry = "FR"
CASE This.Value = 3
ThisForm.cCountry = "DE"
CASE This.Value = 4
ThisForm.cCountry = "GB"
CASE This.Value = 5
ThisForm.cCountry = "IT"
CASE This.Value = 6
ThisForm.cCountry = ""
ENDCASE
ThisForm.ResetArray()
ENDPROC
ADD OBJECT opgListValue as OptionGroup WITH ;
Top = 150, ;
Left = ThisForm.Width - 126, ;
ButtonCount = 3, ;
Value = 1, ;
AutoSize = .T., ;
Anchor = 9
PROCEDURE opgListValue.Init()
LOCAL loButton
FOR i = 1 TO This.ButtonCount
WITH This.Buttons(i)
.AutoSize = .T.
.Caption = ICASE(i = 1, "Code", i = 2, "Item", "Quantity")
ENDWITH
ENDFOR
ENDPROC
PROCEDURE opgListValue.Click()
ThisForm.lstList.BoundColumn = This.Value
ThisForm.ResetArray()
ENDPROC
ADD OBJECT lstList as ListBox WITH ;
Top = 12, ;
Left = 12, ;
Width = ThisForm.Width - 144, ;
Height = ThisForm.Height - 24, ;
ItemBackColor = RGB(0, 240, 240), ;
Anchor = 15, ;
RowSourceType = 6, ;
RowSource = "cItemCode, cItemName, iQuantity", ;
ColumnCount = 4, ;
ColumnWidths = "54, 120, 48, 0", ;
Multiselect = .T., ;
IncrementalSearch = .T.
PROCEDURE lstList.Click()
IF ASCAN(Thisform.aSelection, ALLTRIM(This.Value)) = 0
ThisForm.aSelection[ALEN(ThisForm.aSelection)] = ALLTRIM(This.Value)
DIMENSION ThisForm.aSelection[ALEN(ThisForm.aSelection) + 1]
ENDIF
ENDPROC
PROCEDURE lstList.Requery()
Select cItemCode, cItemName, iQuantity ;
FROM csrOne ;
WHERE cCountry = ThisForm.cCountry ;
ORDER BY 1 ;
INTO CURSOR csrCars
ENDPROC
PROCEDURE lstList.Init()
This.Requery()
ENDPROC
ADD OBJECT cmdShow as CommandButton WITH ;
Top = 216, ;
Left = ThisForm.Width - 126, ;
Height = 36, ;
BackColor = RGB(0, 240, 240), ;
Caption = "Show Selection"
PROCEDURE cmdShow.Click()
FOR i = 1 TO ALEN(ThisForm.aSelection)
IF VARTYPE(ThisForm.aSelection[i]) = "C"
WAIT WINDOW + ThisForm.aSelection[i] TIMEOUT 3
ENDIF
ENDFOR
Thisform.ResetArray()
ENDPROC
PROCEDURE ResetArray()
DIMENSION ThisForm.aSelection[1]
ThisForm.aSelection[1] = .F.
ThisForm.lstList.Requery
ENDPROC
PROCEDURE Load()
CREATE CURSOR csrOne (cItemCode C(5), cItemName C(15), iQuantity I , cCountry C(2))
INSERT INTO csrOne VALUES ("AAAAA", "GMG X1", 5, "US")
INSERT INTO csrOne VALUES ("AAAAB", "GMG Y2", 4, "US")
INSERT INTO csrOne VALUES ("AAAAC", "Renault Zoe", 12, "FR")
INSERT INTO csrOne VALUES ("AAAAD", "Renault Twizzy", 3, "FR")
INSERT INTO csrOne VALUES ("AAAAE", "Renault Twingo", 17, "FR")
INSERT INTO csrOne VALUES ("AAAAF", "BMW 3", 15, "DE")
INSERT INTO csrOne VALUES ("AAAAG", "BMW 5", 25, "DE")
INSERT INTO csrOne VALUES ("AAAAH", "VW Golf", 51, "DE")
INSERT INTO csrOne VALUES ("AAAAI", "Audi A7", 14, "DE")
INSERT INTO csrOne VALUES ("AAAAJ", "Austin", 11, "GB")
INSERT INTO csrOne VALUES ("AAAAK", "Triumph", 9, "GB")
INSERT INTO csrOne VALUES ("AAAAL", "Morgan", 9, "GB")
INSERT INTO csrOne VALUES ("AAAAM", "Alfa Romeo", 6, "IT")
INSERT INTO csrOne VALUES ("AAAAN", "Fiat", 5, "IT")
INSERT INTO csrOne VALUES ("AAAAO", "Maserati", 2, "IT")
INSERT INTO csrOne VALUES ("AAAAP", "Peugeot 403", 2, "FR")
PROCEDURE Destroy()
ThisForm.Release
CLEAR Events
ENDPROC
ENDDEFINE