Hi,
I just found an interesting behaviour of a listbox when a messagebox or some other things (WAIT WINDOW, etc.) are done during the When event (? THIS.Value works fine). The idea was to ask the users, if they want to save changes (if there are any) before allowing them to change to another item in the listbox. Here's what can be done to see that behaviour and the results:
1) Ignore the first messagebox coming up.
2) Click on any item in the list -> messagebox displays the value of the clicked item
3) Click on another item in the list -> messagebox displays the value of the clicked item
4) Click in the textbox
5) Click on any item in the list -> messagebox displays the value of the *old* selected item, not of the currently clicked one, but the item is selected (at least it seems so)
6) Click back in the textbox -> The listbox selects the item where we've been on in step 3
Verified in VFP6 and 7.
Am I missing something here or is this behaviour common knowledge? I'm running into this for the first time, but I hadn't got the idea of putting a messagebox in the When event until now :) It seems, as if the listbox wasn't designed to do these things ...
Not really a problem at the moment. I'll put the question in the Valid event, though it would be nicer in the When event (no doubleclick and no additional button needed and the listbox would reflect the record the user is currently on).
Update: It's the same behaviour regardless of using an Alias or AddItem to fill the list. In the meantime I found a, well, not very clean workaround. Doing a KEYBOARD ' ' in the GotFocus event runs the when event a second time and the list now correctly reflects the changes.
Any comments and hints welcome.
Thanks,
Armin
DEFINE CLASS lsttest AS form
Top = 0
Left = 0
Height = 253
Width = 648
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT list1 AS listbox WITH ;
ColumnCount = 1, ;
RowSourceType = 1, ;
RowSource = "c_test", ;
Height = 170, ;
Left = 44, ;
Top = 32, ;
Width = 180, ;
Name = "List1"
ADD OBJECT text1 AS textbox WITH ;
Height = 23, ;
Left = 320, ;
Top = 56, ;
Width = 100, ;
Name = "Text1"
PROCEDURE Load
CREATE CURSOR C_TEST (f1 C(10) )
INSERT INTO C_TEST VALUES ("Line 1")
INSERT INTO C_TEST VALUES ("Line 2")
INSERT INTO C_TEST VALUES ("Line 3")
INSERT INTO C_TEST VALUES ("Line 4")
INSERT INTO C_TEST VALUES ("Line 5")
ENDPROC
PROCEDURE list1.When
MESSAGEBOX( THIS.Value )
ENDPROC
ENDDEFINE