Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
2 ListBox questions
Message
From
20/06/2014 17:00:43
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
2 ListBox questions
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01602159
Message ID:
01602159
Views:
49
I have a form with a list box. I want to disable some of the items in the listbox. So I put a backslash in the front of all the items I need to disable. My code looks something like
SELECT somefield FROM sometable WHERE conditions INTO CURSOR somecursor READWRITE
SCAN
    IF disable_condition
        REPLACE somefield WITH "\" + somefield
    ENDIF
ENDSCAN

WITH myListBox
    .RowSourceType = 2 && alias
    .RowSource = "somecoursor"
ENDWITH
When the listbox displays, it shows the backslash in the item and none of the items are disabled.

Question 1: Is this expected behavior when using an alias? If so, I didn't find it documented (although I could easily have missed it).

Second Try - Using an array
I added an array as a form property and modified the code to be
SELECT somefield FROM sometable WHERE conditions INTO CURSOR somecursor READWRITE
SCAN
    IF disable_condition
        REPLACE somefield WITH "\" + somefield
    ENDIF
ENDSCAN

DIME thisform.aMyListBox[RECCOUNT("somecursor")]  && Copy to array only copies to the current length of the array
COPY TO ARRAY thisform.aMyListBox
WITH myListBox
    .RowSourceType = 5 && array
    .RowSource = "thisform.aMyListBox"
ENDWITH
Now all the items I want to be disabled show in the disabled color. If you double-click on a disabled item nothing will happen.

But........If I click on an item and then use the arrow keys the disabled items are not bypassed. Pressing the Enter key while
pointing to a disabled item will fire the DblClick code, allowing the user to get around the item being disabled.

I can easily get around this
**In ListBox DblClick code
IF thisform.aMyListBox[this.ListIndex] = "\"
    RETURN 0
ENDIF

.....rest of code
but...

Question 2: Is this correct behavior for disabled items in the sense that disabled is only supposed to apply to mouse clicks?

Thanks...........Rich
Next
Reply
Map
View

Click here to load this message in the networking platform