Skip to content

Latest commit

 

History

History

Q131300

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
layout title permalink
page
Q131300: PRB: Clicking a Disabled Item in a List Box Selects It
/kb/131/Q131300/

Q131300: PRB: Clicking a Disabled Item in a List Box Selects It

{% raw %}

Article: Q131300
Product(s): Microsoft FoxPro
Version(s): WINDOWS:3.0
Operating System(s): 
Keyword(s): kbcode
Last Modified: 15-FEB-2000

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual FoxPro for Windows, version 3.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

One or several items in a list box are disabled. If a disabled element is
clicked and then enabled, it becomes the selected item in the list.

CAUSE
=====

The value property of the combo box determines which item is displayed. This
property is modified when you scroll through a list and the LISTINDEX property
varies. Clicking any item in a list, even if it is disabled, changes the
LISTINDEX property. If the element is then enabled, the LISTINDEX property is
still set to this item, and the list box value is set to the value of the
element.

WORKAROUND
==========

An alternative is to compare the elements referred by the LISTINDEX and the
VALUE properties. If the VALUE property of the combo box is different from the
value of the element referred by LISTINDEX, reset the listindex property to the
value property. You can then enable the list element.


STATUS
======

This behavior is by design.

MORE INFORMATION
================

The following example program illustrates a workaround to the behavior
described. It displays a form with a combo box and a command button. The command
button enables all of the items in the list. When the button is clicked, the
program checks if the value of the combo box corresponds to the listindex. If it
does not, the listindex is reset.

To run this sample program, copy and paste the code into a program file (.PRG
file), and run it. When the list is displayed, click the third element, which is
disabled. Then click the command button. The element displayed in the text part
of the combo box does not change.

Example Workaround Code
-----------------------

  oForm1=CREATE('myform')
  oForm1.SHOW

  *:*************************************************************************
  *:
  *: Class: myform  BaseClass: FORM
  *:
  *:*************************************************************************
  DEFINE CLASS myform AS FORM
        Dimension astep(4,1)
        WindowType=1
        ADD OBJECT combo1 AS COMBOBOX WITH HEIGHT = 37,LEFT = 48,;
          STYLE = 2,TOP = 24
        ADD OBJECT cmdenable AS COMMANDBUTTON WITH TOP = 72,LEFT = 48,;
          HEIGHT = 37,WIDTH = 157,CAPTION = "Enable Steps 2-4"
        PROCEDURE cmdenable.CLICK
           DO CASE
           * The case statement takes into account the fact that the
           * value can be a character. It then goes through the list
           * and finds the index that corresponds to the current value
           * and resets the listindex.
           CASE TYPE('THISFORM.COMBO1.VALUE')="C"
              IF THISFORM.combo1.VALUE <> ;
                 THISFORM.combo1.LIST(THISFORM.combo1.LISTINDEX)
                 i = 1
                 lexit=.F.
                 DO WHILE i <= THISFORM.combo1.LISTCOUNT AND lexit=.F.
                    IF THISFORM.combo1.LIST(i)=THISFORM.combo1.VALUE
                       nNewIndex=i
                       lexit=.T.
                    ENDIF
                    i=i+1
                 ENDDO
                  THISFORM.combo1.LISTINDEX=nNewIndex
                 ENDIF

           CASE TYPE('Thisform.combo1.value')="N"
               IF THISFORM.combo1.VALUE<> THISFORM.combo1.LISTINDEX
                 THISFORM.combo1.LISTINDEX=THISFORM.combo1.VALUE
              ENDIF
           ENDCASE

           FOR m.i = 2 TO 4
              THisform.aStep[m.i, 1] = STRTRAN(Thisform.aStep[m.i, 1], '\')
           ENDFOR

           THISFORM.combo1.REQUERY

        ENDPROC

        PROCEDURE INIT
           This.aStep[1,1] = 'Step 1'
           This.aStep[2,1] = '\Step 2'
           This.aStep[3,1] = '\Step 3'
           This.aStep[4,1] = '\Step 4'
           THIS.combo1.ROWSOURCETYPE = 5
           THIS.combo1.ROWSOURCE = 'Thisform.aStep'
           THIS.combo1.VALUE = 1
        ENDPROC
     ENDDEFINE


Additional query words: VFoxWin

======================================================================
Keywords          : kbcode 
Technology        : kbVFPsearch kbAudDeveloper kbVFP300
Version           : WINDOWS:3.0

=============================================================================

{% endraw %}